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:1 by , 10 years ago
Has patch: | set |
---|
comment:2 by , 10 years ago
Needs documentation: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
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 , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
https://github.com/django/django/pull/3797