mybuddy/babybuddy/mixins.py

31 lines
878 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2022-02-10 00:00:30 +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
2022-02-10 00:00:30 +00:00
@method_decorator(never_cache, name="dispatch")
class LoginRequiredMixin(LoginRequiredMixInBase):
pass
2022-02-10 00:00:30 +00:00
@method_decorator(never_cache, name="dispatch")
class PermissionRequiredMixin(PermissionRequiredMixinBase):
2022-02-10 00:00:30 +00:00
login_url = "/login"
2022-02-10 00:00:30 +00:00
@method_decorator(never_cache, name="dispatch")
class StaffOnlyMixin(AccessMixin):
"""
Verify the current user is staff.
"""
2022-02-10 00:00:30 +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)