-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Code of Conduct
- I agree to follow Django's Code of Conduct
Feature Description
This is a minor enhancement to add superuser_required
to django.contrib.auth.decorators
. Since superuser (aka admin user) is core of Django I see it would be useful to have it as "battery included" in core of Django.
Problem
That would resolve a problem that we create from project to project, that decorator which for my point of view, suits great at Django core (since we have a as a native is_superuser
field on which rely django.contrib.admin
and other custom parts of project which we develop.
Request or proposal
proposal
Additional Details
No response
Implementation Suggestions
def superuser_required(
function=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 log-in page if necessary.
"""
actual_decorator = user_passes_test(
lambda u: u.is_authenticated and u.is_superuser,
login_url=login_url,
redirect_field_name=redirect_field_name,
)
if function:
return actual_decorator(function)
return actual_decorator
czue, gav-fyi, meeb, danielnieto, frankwiles and 5 morecarltongibson, shangxiao and miguel550czue, gav-fyi, UnknownPlatypus, meeb, collinanderson and 1 more
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Idea