Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2200 closed enhancement (wontfix)

Generic Views should have user_passes_test=func argument

Reported by: django@… Owned by: jacob
Component: Generic views Version: master
Severity: normal Keywords: login_required user_passes_test generic view
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


django.views.generic.create_update.*_object Generic Views allow for the argument 'login_required=True' which behaves just like the auth decorator of the same name.

Many times just being logged in is not enough, but certain permissions are required for a view (reporter vs. editor vs. reviewer etc.)
Currently you need to write a custom generic view to get the auth user_passes_test decorator functionality.

It would greatly simplify things if the generic views accepted a 'user_passes_test=func' argument.

Change History (2)

comment:1 Changed 9 years ago by adrian

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

You can wrap the generic view like so:

def my_view(request, *args, **kwargs):
    if not request.user.has_perm('foo'):
        return HttpResponseRedirect('/login/')
    return create_update(request, *args, **kwargs)

comment:2 Changed 9 years ago by anonymous

I understand that it can be wrapped easilly, you can also do:

def my_view(request, *args, **kwargs):
    return create_update(request, *args, **kwargs)

But there is a login_required shortcut directly on the generic views. Just thought it would be a good addition.

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