2017-12-13 18:49:10 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-05-20 21:40:09 +00:00
|
|
|
from django.contrib.auth.mixins import AccessMixin, PermissionRequiredMixin
|
|
|
|
|
|
|
|
|
|
|
|
class PermissionRequired403Mixin(PermissionRequiredMixin):
|
|
|
|
"""
|
|
|
|
Raise an exception instead of redirecting to login.
|
|
|
|
"""
|
|
|
|
raise_exception = True
|
2017-12-13 18:49:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class StaffOnlyMixin(AccessMixin):
|
|
|
|
"""
|
|
|
|
Verify the current user is staff.
|
|
|
|
"""
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
if not request.user.is_staff:
|
|
|
|
return self.handle_no_permission()
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|