Code

Opened 8 years ago

Closed 7 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@… 8 years ago.
[patch] permit wrapping of change_list et al

Download all attachments as: .zip

Change History (10)

Changed 8 years ago by garthk@…

[patch] permit wrapping of change_list et al

comment:1 Changed 8 years ago by anonymous

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

comment:2 Changed 8 years ago by mtredinnick

  • Type changed from defect to enhancement

comment:3 Changed 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:4 Changed 7 years ago by jacob

  • Resolution fixed deleted
  • Status changed from closed to reopened

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

Reopening.

comment:5 Changed 7 years ago by garthk@…

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

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

  • Triage Stage changed from Unreviewed to Design 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 7 years ago by Gary Wilson <gary.wilson@…>

  • Cc gary.wilson@… added

comment:8 Changed 7 years ago by garthk@…

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

comment:9 Changed 7 years ago by ubernostrum

  • Resolution set to wontfix
  • Status changed from reopened to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.