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 Tim Graham, 9 years ago

Component: UncategorizedUtilities
Triage Stage: UnreviewedAccepted
Version: 1.8master

comment:2 by Rigel Di Scala, 9 years ago

Owner: changed from nobody to Rigel Di Scala
Status: newassigned

Taking a look at it...

comment:3 by Rigel Di Scala, 9 years ago

Has patch: set

comment:4 by Tim Graham, 9 years ago

Patch needs improvement: set

comment:5 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 3bdaaf67:

Fixed #25146 -- Allowed method_decorator() to decorate classes.

Note: See TracTickets for help on using tickets.
Back to Top