mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-28 16:03:43 +03:00
18 lines
621 B
Python
18 lines
621 B
Python
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
|
from django.views.generic.detail import SingleObjectMixin
|
|
|
|
|
|
class SuperUserRequiredMixin(LoginRequiredMixin, UserPassesTestMixin):
|
|
def test_func(self):
|
|
return self.request.user.is_superuser
|
|
|
|
|
|
class HasPermissions(SingleObjectMixin):
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
has_perm = False
|
|
if self.request.user.is_authenticated:
|
|
has_perm = self.object.user == self.request.user
|
|
context["has_permissions"] = has_perm
|
|
return context
|