Opened 19 years ago

Closed 19 years ago

Last modified 19 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: dev
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: no UI/UX: no

Description

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 by Adrian Holovaty, 19 years ago

Resolution: wontfix
Status: newclosed

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 by anonymous, 19 years ago

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

@login_required
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