plateforme-tfjm2/apps/member/views.py

56 lines
1.9 KiB
Python

from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.http import FileResponse
from django.utils.translation import gettext_lazy as _
from django.views import View
from django.views.generic import CreateView
from django_tables2 import SingleTableView
from tournament.views import AdminMixin
from .forms import SignUpForm
from .models import TFJMUser, Document
from .tables import UserTable
class CreateUserView(CreateView):
model = TFJMUser
form_class = SignUpForm
template_name = "registration/signup.html"
class DocumentView(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs):
doc = Document.objects.get(file=self.kwargs["file"])
if not request.user.admin:
raise PermissionDenied
return FileResponse(doc.file, content_type="application/pdf")
class ProfileListView(LoginRequiredMixin, AdminMixin, SingleTableView):
model = TFJMUser
queryset = TFJMUser.objects.order_by("role", "last_name", "first_name")
table_class = UserTable
template_name = "member/profile_list.html"
extra_context = dict(title=_("All profiles"))
class OrphanedProfileListView(LoginRequiredMixin, AdminMixin, SingleTableView):
model = TFJMUser
queryset = TFJMUser.objects.filter((Q(role="2coach") | Q(role="3participant")) & Q(team__isnull=True))\
.order_by("role", "last_name", "first_name")
table_class = UserTable
template_name = "member/profile_list.html"
extra_context = dict(title=_("Orphaned profiles"))
class OrganizersListView(LoginRequiredMixin, AdminMixin, SingleTableView):
model = TFJMUser
queryset = TFJMUser.objects.filter(Q(role="0admin") | Q(role="1volunteer"))\
.order_by("role", "last_name", "first_name")
table_class = UserTable
template_name = "member/profile_list.html"
extra_context = dict(title=_("Organizers"))