ernestophone.ens.fr/gestion/mixins.py

81 lines
2.5 KiB
Python
Raw Normal View History

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
2021-10-06 13:46:45 +02:00
2022-01-06 13:11:16 +01:00
2021-10-06 13:46:45 +02:00
class ChefEventRequiredMixin(UserPassesTestMixin):
def test_func(self):
user = self.request.user
2022-01-06 13:11:16 +01:00
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
)
2021-10-06 13:46:45 +02:00
return is_chef or is_chef_event
2021-10-23 11:16:07 +02:00
2022-01-06 13:11:16 +01:00
2021-10-23 11:16:07 +02:00
class ChefInstruRequiredMixin(UserPassesTestMixin):
def test_func(self):
user = self.request.user
2022-01-06 13:11:16 +01:00
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
)
2021-10-23 11:16:07 +02:00
return is_chef or is_chef_instru
class ChefComRequiredMixin(UserPassesTestMixin):
def test_func(self):
user = self.request.user
2022-01-06 13:11:16 +01:00
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
)
2021-10-23 11:16:07 +02:00
return is_chef or is_chef_com
2022-01-06 13:11:16 +01:00
2022-02-05 16:18:00 +01:00
2022-01-11 16:21:22 +01:00
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
2022-01-06 13:11:16 +01:00
2021-10-23 11:16:07 +02:00
class AllChefRequiredMixin(UserPassesTestMixin):
def test_func(self):
user = self.request.user
2022-01-06 13:11:16 +01:00
is_chef = (
(user is not None) and hasattr(user, "profile") and user.profile.is_chef
)
2021-10-23 11:16:07 +02:00
is_su = (user is not None) and user.is_superuser
2022-01-06 13:11:16 +01:00
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
)
2022-01-11 16:21:22 +01:00
is_chef_mu = (
2022-02-05 16:18:00 +01:00
(user is not None) and hasattr(user, "profile") and user.profile.is_chef_mu
2022-01-11 16:21:22 +01:00
)
return is_chef or is_chef_com or is_chef_event or is_su or is_chef_mu