1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-11-30 08:53:04 +00:00
plateforme-tfjm2/tfjm/views.py
Yohann D'ANELLO daac77ba57
Linting
2021-01-17 16:23:48 +01:00

32 lines
1.1 KiB
Python

# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.mixins import LoginRequiredMixin
from haystack.generic_views import SearchView
class AdminMixin(LoginRequiredMixin):
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated and not request.user.registration.is_admin:
self.handle_no_permission()
return super().dispatch(request, *args, **kwargs)
class VolunteerMixin(LoginRequiredMixin):
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated and not request.user.registration.is_volunteer:
self.handle_no_permission()
return super().dispatch(request, *args, **kwargs)
class UserMixin(LoginRequiredMixin):
def dispatch(self, request, *args, **kwargs):
user = request.user
if user.is_authenticated and not user.registration.is_admin and user.registration.pk != kwargs["pk"]:
self.handle_no_permission()
return super().dispatch(request, *args, **kwargs)
class AdminSearchView(AdminMixin, SearchView):
pass