mirror of
https://github.com/xingsu1021/pthelper.git
synced 2026-02-11 14:15:19 +08:00
19 lines
692 B
Python
19 lines
692 B
Python
#coding=utf-8
|
|
from django.contrib.auth import REDIRECT_FIELD_NAME
|
|
from django.contrib.admin.views.decorators import user_passes_test
|
|
|
|
#REDIRECT_FIELD_NAME 默认 next
|
|
def superuser_required(view_func=None, redirect_field_name=REDIRECT_FIELD_NAME,
|
|
login_url=None):
|
|
"""
|
|
Decorator for views that checks that the user is logged in and is a
|
|
superuser, redirecting to the login page if necessary.
|
|
"""
|
|
actual_decorator = user_passes_test(
|
|
lambda u: u.is_active and u.is_superuser,
|
|
login_url=login_url,
|
|
redirect_field_name=redirect_field_name
|
|
)
|
|
if view_func:
|
|
return actual_decorator(view_func)
|
|
return actual_decorator |