The following would be equivalent:
{{{
#!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)
}}}
{{{
#!python
@method_decorator(login_required, name='dispatch')
class ProtectedView(generic.TemplateView):
template_name = 'secret.html'
}}}
This idea comes from a comment by timgraham on #25138.
--
Ticket URL: <https://code.djangoproject.com/ticket/25146>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: Uncategorized => Utilities
* needs_tests: => 0
* version: 1.8 => master
* needs_docs: => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/25146#comment:1>
* status: new => assigned
* owner: nobody => zedr
Comment:
Taking a look at it...
--
Ticket URL: <https://code.djangoproject.com/ticket/25146#comment:2>
* has_patch: 0 => 1
Comment:
Pull request: https://github.com/django/django/pull/5031
--
Ticket URL: <https://code.djangoproject.com/ticket/25146#comment:3>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/25146#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"3bdaaf6777804d33ee46cdb5a889b8cc544a91f1" 3bdaaf67]:
{{{
#!CommitTicketReference repository=""
revision="3bdaaf6777804d33ee46cdb5a889b8cc544a91f1"
Fixed #25146 -- Allowed method_decorator() to decorate classes.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25146#comment:5>