[Django] #25235: Class based view decoration

9 views
Skip to first unread message

Django

unread,
Aug 6, 2015, 10:04:54 AM8/6/15
to django-...@googlegroups.com
#25235: Class based view decoration
-------------------------------------+-------------------------------------
Reporter: zauddelig | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Utilities | Version: 1.8
Severity: Normal | Keywords: documentation, class
| based views, utilities, decorators
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
The class based views decoration documentation is in my opinion ugly and I
think is keeping some beginners from class based views.

Based on that ,one has three methods:

1. Use Multi Inheritance, which is both risky and dreadful, imho is too
easy to have side effects, still is the more clean solution described.

2. Use method_decorator, which is better if not that you have to wrap
every decorator function inside of it and are forced rewrite `dispatch`.

3. wrapping directly the `Klass.as_view()`, better but as documented it
seem more a problem than anything.

The advantage of the third method is that you preserve the logic of the
Classes, so that the same View can change, more or less slightly, it's
logic in different contexts.

I usually use solutions like this:

{{{
view = reduce(
lambda x, f: f(x),
(
third_decorator,
second_decorator,
first_decorator,
),
ViewKlass.as_view()
)
}}}

The good thing is that you can wrap group of common decorators in a single
iterable.

I don't know if it would be better to have a `django.utils` to do this or
just add to documentation this or some similar method.

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

Django

unread,
Aug 6, 2015, 11:48:03 AM8/6/15
to django-...@googlegroups.com
#25235: Class based view decoration
-------------------------------------+-------------------------------------
Reporter: zauddelig | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Utilities | Version: 1.8
Severity: Normal | Resolution:
Keywords: documentation, | Triage Stage:
class based views, utilities, | Unreviewed
decorators |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

[https://groups.google.com/d/topic/django-
developers/gnctZWh0YsY/discussion django-developers discussion]. (For
future reference, it's usually better to wait until the mailing list
thread reaches a conclusion of what should be done before opening a
ticket.)

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

Django

unread,
Aug 7, 2015, 6:59:09 PM8/7/15
to django-...@googlegroups.com
#25235: Document alternate syntax for class-based view decoration

-------------------------------------+-------------------------------------
Reporter: zauddelig | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Utilities | Version: 1.8
Severity: Normal | Resolution: wontfix

Keywords: documentation, | Triage Stage:
class based views, utilities, | Unreviewed
decorators |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

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


Comment:

Closing as #25146 seems to address this concern as discussed on the
mailing list.

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

Reply all
Reply to author
Forward
0 new messages