[Django] #32399: Allow method_decorator to handle multiple functions

14 views
Skip to first unread message

Django

unread,
Jan 30, 2021, 12:35:36 PM1/30/21
to django-...@googlegroups.com
#32399: Allow method_decorator to handle multiple functions
------------------------------------------+------------------------
Reporter: Alexey Kotenko | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
Allowing `method_decorator` to handle multiple function names would avoid
invoking it multiple times:

{{{#!python
@method_decorator(login_required, name='get')
@method_decorator(login_required, name='post')
class SimpleView(View):
...
}}}

Instead of this lets modify function to polymorpic style:
{{{#!python
@method_decorator(login_required, name=['get', 'post'])
class SimpledView(View):
...
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32399>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 30, 2021, 12:36:05 PM1/30/21
to django-...@googlegroups.com
#32399: Allow method_decorator to handle multiple functions
--------------------------------+--------------------------------------

Reporter: Alexey Kotenko | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Description changed by Alexey Kotenko:

Old description:

> Allowing `method_decorator` to handle multiple function names would avoid
> invoking it multiple times:
>
> {{{#!python
> @method_decorator(login_required, name='get')
> @method_decorator(login_required, name='post')
> class SimpleView(View):
> ...
> }}}
>
> Instead of this lets modify function to polymorpic style:
> {{{#!python
> @method_decorator(login_required, name=['get', 'post'])
> class SimpledView(View):
> ...
> }}}

New description:

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

{{{#!python
@method_decorator(login_required, name='get')
@method_decorator(login_required, name='post')
class SimpleView(View):
...
}}}

Instead of this lets modify function to polymorpic style:
{{{#!python
@method_decorator(login_required, name=['get', 'post'])

class SimpleView(View):
...
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32399#comment:1>

Django

unread,
Jan 30, 2021, 12:38:06 PM1/30/21
to django-...@googlegroups.com
#32399: Allow method_decorator to handle multiple functions
--------------------------------+--------------------------------------

Reporter: Alexey Kotenko | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

Comment (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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32399#comment:2>

Django

unread,
Feb 1, 2021, 7:20:18 AM2/1/21
to django-...@googlegroups.com
#32399: Allow method_decorator() to accept a list/tuple of method names.
--------------------------------+--------------------------------------

Reporter: Alexey Kotenko | Owner: nobody
Type: New feature | Status: closed
Component: Utilities | Version: master
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32399#comment:3>

Reply all
Reply to author
Forward
0 new messages