Fixed #24294 -- Allowed staff_member_required decorator to handle args.

This commit is contained in:
Andrei Kulakov 2015-02-06 16:45:46 -05:00 committed by Tim Graham
parent 4e8b167e4d
commit 08572e8d12
4 changed files with 23 additions and 4 deletions

View file

@ -2,13 +2,17 @@ from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import user_passes_test
def staff_member_required(view_func, redirect_field_name=REDIRECT_FIELD_NAME, login_url='admin:login'):
def staff_member_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
login_url='admin:login'):
"""
Decorator for views that checks that the user is logged in and is a staff
member, displaying the login page if necessary.
member, redirecting to the login page if necessary.
"""
return user_passes_test(
actual_decorator = user_passes_test(
lambda u: u.is_active and u.is_staff,
login_url=login_url,
redirect_field_name=redirect_field_name
)(view_func)
)
if view_func:
return actual_decorator(view_func)
return actual_decorator