mirror of
https://github.com/django/django.git
synced 2025-11-14 17:32:38 +00:00
Fixed #24294 -- Allowed staff_member_required decorator to handle args.
This commit is contained in:
parent
4e8b167e4d
commit
08572e8d12
4 changed files with 23 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue