2017-12-13 18:49:10 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-09-17 02:34:33 +00:00
|
|
|
from django.contrib.auth.mixins import AccessMixin, \
|
|
|
|
LoginRequiredMixin as LoginRequiredMixInBase, \
|
|
|
|
PermissionRequiredMixin as PermissionRequiredMixinBase
|
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
from django.views.decorators.cache import never_cache
|
2018-05-20 21:40:09 +00:00
|
|
|
|
|
|
|
|
2021-09-17 02:34:33 +00:00
|
|
|
@method_decorator(never_cache, name='dispatch')
|
|
|
|
class LoginRequiredMixin(LoginRequiredMixInBase):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(never_cache, name='dispatch')
|
|
|
|
class PermissionRequiredMixin(PermissionRequiredMixinBase):
|
|
|
|
login_url = '/login'
|
2017-12-13 18:49:10 +00:00
|
|
|
|
|
|
|
|
2021-09-17 02:34:33 +00:00
|
|
|
@method_decorator(never_cache, name='dispatch')
|
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)
|