blob: c1b63ba64d727c1e2d15a462ee9350c2c9a27b0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import user_passes_test
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, redirecting to the login page if necessary.
"""
actual_decorator = user_passes_test(
lambda u: u.is_active and u.is_staff,
login_url=login_url,
redirect_field_name=redirect_field_name,
)
if view_func:
return actual_decorator(view_func)
return actual_decorator
|