﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25138	Easier decoration of class-based views	George Brocklehurst	nobody	"The class-based view documentation [#link1 (1)] recommends:

    To decorate every instance of a class-based view, you need to decorate the class definition itself. To do this you apply the decorator to the `dispatch()` method of the class.

This can get a little syntactically cumbersome:

{{{
#!python
class ProtectedView(generic.TemplateView):
    template_name = 'secret.html'
 
    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(ProtectedView, self).dispatch(*args, **kwargs)
}}}

Instead, we could provide a decorator that can be applied to the view class:

{{{
#!python
@dispatch_decorator(login_required)
class ProtectedView(generic.TemplateView):
    template_name = 'secret.html'
}}}

I've spiked on a quick implementation of this, which seems to work [#link2 (2)]. I'm happy to write that up as a proper PR with tests, if it seems like it would be useful.

[=#link1 (1)]: https://docs.djangoproject.com/en/1.8/topics/class-based-views/intro/#decorating-the-class
[=#link2 (2)]: https://gist.github.com/georgebrock/24b831c65b09b309c618"	New feature	closed	Generic views	1.8	Normal	wontfix	views decorators		Unreviewed	0	0	0	0	0	0
