API for simpler (permission or any) checks for generic view classes
|Reported by:||Ciantic||Owned by:||nobody|
|Cc:||tomchristie, selwin, amirouche.boubekki@…||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The generic class based views are difficult and cumbersome to decorate, why even trying to reuse the decorator functions? Why not implement simple functions that would do the checking.
I propose following API for checking the class based views (in this case just permissions):
from django.contrib.auth.viewchecks import login_required, has_perms class ProtectedView(TemplateView): template_name = 'secret.html' dispatch_checks = (login_required, has_perms('auth.change_user'),)
(Notice that I used hypothetical django.contrib.auth.viewchecks)
dispatch_checks is list of functions (request, *args, **kwargs) -> bool if allowed to dispatch. Thus the has_perms('auth.change_user') should return function.
Above would also allow overriding the dispatch_checks tuple in subclassed views which I think is very important.
I'm working on a simple patch for django.contrib.auth and to View class to allow this, these checker functions should be reusable in decorators.
Change History (18)
comment:1 Changed 5 years ago by Ciantic
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:3 Changed 5 years ago by russellm
- Triage Stage changed from Unreviewed to Design decision needed
comment:13 Changed 2 years ago by apollo13
- Triage Stage changed from Design decision needed to Accepted
comment:16 Changed 2 years ago by garrypolley
- Resolution set to wontfix
- Status changed from new to closed
comment:17 Changed 2 years ago by mjtamlyn
- Resolution wontfix deleted
- Status changed from closed to new