Opened 10 years ago

Closed 10 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

Description

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.

Change History (3)

comment:2 by Loic Bistuer, 10 years ago

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 by Loic Bistuer <loic.bistuer@…>, 10 years ago

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