2017-12-13 18:49:10 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2022-02-10 00:00:30 +00:00
|
|
|
from django.contrib.auth.mixins import (
|
|
|
|
AccessMixin,
|
|
|
|
LoginRequiredMixin as LoginRequiredMixInBase,
|
|
|
|
PermissionRequiredMixin as PermissionRequiredMixinBase,
|
|
|
|
)
|
2021-09-17 02:34:33 +00:00
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
from django.views.decorators.cache import never_cache
|
2018-05-20 21:40:09 +00:00
|
|
|
|
|
|
|
|
2022-02-10 00:00:30 +00:00
|
|
|
@method_decorator(never_cache, name="dispatch")
|
2021-09-17 02:34:33 +00:00
|
|
|
class LoginRequiredMixin(LoginRequiredMixInBase):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-02-10 00:00:30 +00:00
|
|
|
@method_decorator(never_cache, name="dispatch")
|
2021-09-17 02:34:33 +00:00
|
|
|
class PermissionRequiredMixin(PermissionRequiredMixinBase):
|
2022-02-10 00:00:30 +00:00
|
|
|
login_url = "/login"
|
2017-12-13 18:49:10 +00:00
|
|
|
|
|
|
|
|
2022-02-10 00:00:30 +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.
|
|
|
|
"""
|
2022-02-10 00:00:30 +00:00
|
|
|
|
2017-12-13 18:49:10 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
if not request.user.is_staff:
|
|
|
|
return self.handle_no_permission()
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|