API for simpler (permission or any) checks for generic view classes
|Reported by:||Jari Pennanen||Owned by:||nobody|
|Cc:||Tom Christie, Selwin Ong, 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
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 6 years ago by
|Patch needs improvement:||unset|