Last active
April 8, 2019 14:12
-
-
Save gtindo/65ce6c0879d1e58f2106bb495b5e3856 to your computer and use it in GitHub Desktop.
A Django mixin for checking user status and redirect
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 django.contrib.auth.mixins import AccessMixin | |
from django.shortcuts import redirect | |
class UserIsStaffRequired(AccessMixin): | |
"""Verify that the current user is staff member.""" | |
def dispatch(self, request, *args, **kwargs): | |
if not request.user.is_authenticated : | |
return self.handle_no_permission() | |
else: | |
if not request.user.is_staff : | |
return redirect("/") | |
return super().dispatch(request, *args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment