[Django] #24055: Keep reference to view class for resolve()

9 views
Skip to first unread message

Django

unread,
Dec 27, 2014, 2:16:32 AM12/27/14
to django-...@googlegroups.com
#24055: Keep reference to view class for resolve()
--------------------------------+--------------------
Reporter: collinanderson | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------
I have some pretty hacky code like this that I'd like to get rid of:

{{{
match = resolve(url_split)
for cl in match.func.__closure__:
if hasattr(cl.cell_contents, 'http_method_names'):
view_class = cl.cell_contents
# etc
if hasattr(cl.cell_contents, 'admin_site'):
admin = cl.cell_contents
if not admin.has_change_permission(etc):
etc
}}}
It would be great if we could keep a reference to the original view class
in these cases.

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

Django

unread,
Dec 27, 2014, 2:18:20 AM12/27/14
to django-...@googlegroups.com
#24055: Keep reference to view class for resolve()
--------------------------------+--------------------------------------

Reporter: collinanderson | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


Comment:

https://github.com/django/django/pull/3797

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

Django

unread,
Jan 14, 2015, 10:28:47 AM1/14/15
to django-...@googlegroups.com
#24055: Keep reference to view class for resolve()
--------------------------------+------------------------------------

Reporter: collinanderson | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

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

* needs_docs: 0 => 1
* stage: Unreviewed => Accepted


Comment:

I agree it'd be nice to enable retrieving the actual class, we already
preserve `__name__`, `__doc__`, etc. we might as well preserve the class
itself.

I was worried that decorators like `login_required` would wipe these
anyway and that it may be too fragile as an API, but apparently it doesn't
happen thanks to `functools.wraps()` preserving `__dict__`.

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

Django

unread,
Jan 17, 2015, 10:09:45 AM1/17/15
to django-...@googlegroups.com
#24055: Keep reference to view class for resolve()
--------------------------------+------------------------------------
Reporter: collinanderson | Owner: nobody
Type: New feature | Status: closed

Component: Generic views | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Loic Bistuer <loic.bistuer@…>):

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


Comment:

In [changeset:"a420f83e7d2e446ca01ef7c13d30c2ef3e975e5c"]:
{{{
#!CommitTicketReference repository=""
revision="a420f83e7d2e446ca01ef7c13d30c2ef3e975e5c"
Fixed #24055 -- Keep reference to view class for resolve()
}}}

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

Reply all
Reply to author
Forward
0 new messages