Opened 9 years ago

Closed 9 years ago

#24055 closed New feature (fixed)

Keep reference to view class for resolve()

Reported by: Collin Anderson Owned by: nobody
Component: Generic views Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


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):

It would be great if we could keep a reference to the original view class in these cases.

Change History (3)

comment:1 Changed 9 years ago by Collin Anderson

Has patch: set

comment:2 Changed 9 years ago by Loic Bistuer

Needs documentation: set
Triage Stage: UnreviewedAccepted

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__.

comment:3 Changed 9 years ago by Loic Bistuer <loic.bistuer@…>

Resolution: fixed
Status: newclosed

In a420f83e7d2e446ca01ef7c13d30c2ef3e975e5c:

Fixed #24055 -- Keep reference to view class for resolve()

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