Created
June 1, 2013 16:45
-
-
Save Alir3z4/5690971 to your computer and use it in GitHub Desktop.
Decorator to check whether user is super user or not If user is not a super-user, it will raise PermissionDenied or 403 Forbidden.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from django.core.exceptions import PermissionDenied | |
def superuser_required(method): | |
""" | |
Decorator to check whether user is super user or not | |
If user is not a super-user, it will raise PermissionDenied or | |
403 Forbidden. | |
""" | |
@wraps(method) | |
def _wrapped_view(request, *args, **kwargs): | |
if request.user.is_superuser is False: | |
raise PermissionDenied | |
return method(request, *args, **kwargs) | |
return _wrapped_view |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment