#put it to your app/shared/decorators.py and than import when required
from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth import REDIRECT_FIELD_NAME
def is_staff(function=None, redirect_field_name=REDIRECT_FIELD_NAME):
"""
Decorator for views that checks that the user is staff, redirecting
to the log-in page if necessary.
Possible usage:
@is_staff
def view....
urlpatterns = patterns('',
(r'^databrowse/(.*)', is_staff(databrowse.site.root)),
)
"""
actual_decorator = user_passes_test(
lambda u: u.is_staff,
redirect_field_name=redirect_field_name
)
if function:
return actual_decorator(function)
return actual_decorator
Comments
uh, there's already a decorator for that built into Django.
I guess it's not not as versatile as yours, since the staff_member_required() decorator always displays the Admin login page, but unless you've got really specific requirements I don't see why you wouldn't want to use the Admin login page.
#
Honestly speaking I wasn't aware
thanks
#