Opened 11 years ago

Closed 9 years ago

#2104 closed enhancement (wontfix)

[patch] Make admin view methods wrappable by user views for non-staff

Reported by: garthk@… Owned by: nobody
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: gary.wilson@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I'm trying to call admin views from my views to greatly simplify my code. My efforts are frustrated by this style of view definition in django.contrib.admin.views.main:

def useful_view_method(request): 
   # ...
useful_view_method = staff_member_required(usefulmethod)

Thanks to the wrapper, the method is useful only to the admin interface unless I make a copy of it. Such a copy is inefficient, error-prone, and requires checking each Django code update.

Making the unprotected view available as follows would let me wrap the view myself to whatever protection level I see fit:

def _useful_view_method(request):
    # ...
useful_view_method = staff_member_required(_useful_view_method)

On a similar line of thinking: change_list needlessly insists on change permission. I'd like it to list regardless, as even mortals should be able to view the table I've got in mind. I can have my change_stage equivalent check permissions and then pass on to either a read-only view method or the "official" change_stage, at least once I can reach around the staff_member_required wrapper.

Attachments (1)

2104.diff (6.7 KB) - added by garthk@… 11 years ago.
[patch] permit wrapping of change_list et al

Download all attachments as: .zip

Change History (10)

Changed 11 years ago by garthk@…

Attachment: 2104.diff added

[patch] permit wrapping of change_list et al

comment:1 Changed 11 years ago by anonymous

Summary: Admin view paranoia limits re-use[patch] Make admin view methods wrappable by user views for non-staff

comment:2 Changed 10 years ago by Malcolm Tredinnick

Type: defectenhancement

comment:3 Changed 10 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [4577]) Fixed #2104: allow somewhat nicer error messages in RequiredIfOtherFieldEquals validator. Thanks, Steven Armstrong

comment:4 Changed 10 years ago by Jacob

Resolution: fixed
Status: closedreopened

Darn it, that commit was supposed to close #2014, not #2104.

Reopening.

comment:5 Changed 10 years ago by garthk@…

If you want to close #2014 with some code, though, feel free. :)

comment:6 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: UnreviewedDesign decision needed

I think it would be nice to be able to re-use some of the admin functionality in other places. The new admin options stuff being talked about will allow you to run multiple admin interface instances and use different authorization checks, so maybe that will fix this ticket.

comment:7 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Cc: gary.wilson@… added

comment:8 Changed 10 years ago by garthk@…

Control over the authorisation checks and URL would definitely help. Where is this "talked about"?

comment:9 Changed 9 years ago by James Bennett

Resolution: wontfix
Status: reopenedclosed

The admin views are going away, to be replaced with a much more customizable AdminSite class.

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