Opened 9 years ago
Closed 9 years ago
#25146 closed New feature (fixed)
Allow method_decorator to work at the class level
Reported by: | George Brocklehurst | Owned by: | Rigel Di Scala |
---|---|---|---|
Component: | Utilities | Version: | dev |
Severity: | Normal | Keywords: | method_decorator |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Allowing method_decorator
to be applied at the class level would avoid situations where a superclass method is re-declared, just to apply a decorator.
The following would be equivalent:
class ProtectedView(generic.TemplateView): template_name = 'secret.html' @method_decorator(login_required) def dispatch(self, *args, **kwargs): return super(ProtectedView, self).dispatch(*args, **kwargs)
@method_decorator(login_required, name='dispatch') class ProtectedView(generic.TemplateView): template_name = 'secret.html'
This idea comes from a comment by timgraham on #25138.
Change History (5)
comment:1 by , 9 years ago
Component: | Uncategorized → Utilities |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | 1.8 → master |
comment:2 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 9 years ago
Patch needs improvement: | set |
---|
Note:
See TracTickets
for help on using tickets.
Taking a look at it...