Opened 2 months ago

Closed 2 months ago

#32399 closed New feature (wontfix)

Allow method_decorator() to accept a list/tuple of method names.

Reported by: Alexey Kotenko Owned by: nobody
Component: Utilities Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alexey Kotenko)

Allowing method_decorator to handle multiple function names would avoid invoking it multiple times:

@method_decorator(login_required, name='get')
@method_decorator(login_required, name='post')
class SimpleView(View):
    ...

Instead of this lets modify function to polymorpic style:

@method_decorator(login_required, name=['get', 'post'])
class SimpleView(View):
    ...

Change History (3)

comment:1 Changed 2 months ago by Alexey Kotenko

Description: modified (diff)

comment:2 Changed 2 months ago by Alexey Kotenko

I created this ticket because I want to get confirmation from the community and contributors that this change is possible. After confirmation I am ready to send PR.

comment:3 Changed 2 months ago by Mariusz Felisiak

Resolution: wontfix
Status: newclosed
Summary: Allow method_decorator to handle multiple functionsAllow method_decorator() to accept a list/tuple of method names.

Thanks for this proposition, I'm not sure it is worth additional complexity. @method_decorator already supports multiple decorators, supporting multiple methods would require a signature change (so a backward incompatible change with a deprecation of the current signature, etc.) or maybe a new decorator e.g. @methods_decorator (probably confusing). Nevertheless we could evaluate a patch if you want to prepare a proof of concept.

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