This could be useful because it's common to decorate views using redundant
sets of decorators inside the same project or subproject, one could argue
that the same result is attained creating a new decorator or a Mixin, yet
an iterable, i. e. a tuple, seem to me more plastic and maintainable
than a class or a function.
This could be also useful if one intend to dynamically decorate
dynamically created classes although this is most probably going to be
useful in less than the 1% of the cases, so actually not significant.
The proposal introduces a polymorphic behaviour to `method_decorator`
which should now accept both function and iterables, so both the following
examples should be valid:
{{{
decorators = (
blacklist_ip,
request_is_cool,
login_required,
)
@method_decorator(decorators,"dispatch")
class ProtectedView(View):
# lot of meaningful code
pass
@method_decorator(login_required, "dispatch")
class LessProtectedView(View):
# lot of meaningful code
pass
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25269>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: Uncategorized => Utilities
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:1>
* needs_docs: 0 => 1
Old description:
New description:
pull request: https://github.com/django/django/pull/5134
--
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:2>
* type: Uncategorized => New feature
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:3>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:4>
Comment (by zauddelig):
I updated the pull requested:
https://github.com/django/django/pull/5134
It was added some documentation to the new behavior pretty much mimicking
the excellent one already done by zedr.
I will squash when the PR is accepted and before it is merged if that is
not a problem.
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:5>
Old description:
> pull request: https://github.com/django/django/pull/5134
New description:
pull request: https://github.com/django/django/pull/5136
--
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:6>
Comment (by zauddelig):
I have done one big mess up while rebasing I closed the PR and Opened
another
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:7>
* needs_docs: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:8>
* keywords: => 1.9
* needs_better_patch: 0 => 1
Comment:
A few more updates are required but this seems to be in mostly good shape.
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:9>
* status: new => assigned
* owner: nobody => timgraham
Comment:
I'm updating the patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:10>
* needs_better_patch: 1 => 0
Comment:
[https://github.com/django/django/pull/5311 Updated PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:11>
* stage: Accepted => Ready for checkin
Comment:
[https://github.com/django/django/pull/5311/ PR #5311] LGTM.
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:12>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"186eb21dc159807dba83148f7c9c50d470745708" 186eb21d]:
{{{
#!CommitTicketReference repository=""
revision="186eb21dc159807dba83148f7c9c50d470745708"
Fixed #25269 -- Allowed method_decorator() to accept a list/tuple of
decorators.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:13>
Comment (by Chris Jerdonek):
FYI, I filed ticket #29253 about the implementation of this feature.
--
Ticket URL: <https://code.djangoproject.com/ticket/25269#comment:14>