ernestophone.ens.fr/gestion/mixins.py
Maurice Debray 5062a1e84e linting
2022-02-05 16:18:00 +01:00

80 lines
2.5 KiB
Python

from django.contrib.auth.mixins import UserPassesTestMixin
class ChefRequiredMixin(UserPassesTestMixin):
def test_func(self):
user = self.request.user
return (user is not None) and hasattr(user, "profile") and user.profile.is_chef
class ChefEventRequiredMixin(UserPassesTestMixin):
def test_func(self):
user = self.request.user
is_chef = (
(user is not None) and hasattr(user, "profile") and user.profile.is_chef
)
is_chef_event = (
(user is not None)
and hasattr(user, "profile")
and user.profile.is_chef_event
)
return is_chef or is_chef_event
class ChefInstruRequiredMixin(UserPassesTestMixin):
def test_func(self):
user = self.request.user
is_chef = (
(user is not None) and hasattr(user, "profile") and user.profile.is_chef
)
is_chef_instru = (
(user is not None)
and hasattr(user, "profile")
and user.profile.is_chef_instru
)
return is_chef or is_chef_instru
class ChefComRequiredMixin(UserPassesTestMixin):
def test_func(self):
user = self.request.user
is_chef = (
(user is not None) and hasattr(user, "profile") and user.profile.is_chef
)
is_chef_com = (
(user is not None) and hasattr(user, "profile") and user.profile.is_chef_com
)
return is_chef or is_chef_com
class ChefMuRequiredMixin(UserPassesTestMixin):
def test_func(self):
user = self.request.user
is_chef = (
(user is not None) and hasattr(user, "profile") and user.profile.is_chef
)
is_chef_mu = (
(user is not None) and hasattr(user, "profile") and user.profile.is_chef_mu
)
return is_chef or is_chef_mu
class AllChefRequiredMixin(UserPassesTestMixin):
def test_func(self):
user = self.request.user
is_chef = (
(user is not None) and hasattr(user, "profile") and user.profile.is_chef
)
is_su = (user is not None) and user.is_superuser
is_chef_com = (
(user is not None) and hasattr(user, "profile") and user.profile.is_chef_com
)
is_chef_event = (
(user is not None)
and hasattr(user, "profile")
and user.profile.is_chef_event
)
is_chef_mu = (
(user is not None) and hasattr(user, "profile") and user.profile.is_chef_mu
)
return is_chef or is_chef_com or is_chef_event or is_su or is_chef_mu