2020-04-29 23:20:50 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.core.exceptions import PermissionDenied
|
2020-04-30 19:07:12 +00:00
|
|
|
from django.db.models import Q
|
2020-04-29 23:20:50 +00:00
|
|
|
from django.http import FileResponse
|
2020-04-30 19:07:12 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-04-29 23:20:50 +00:00
|
|
|
from django.views import View
|
2020-04-29 13:29:01 +00:00
|
|
|
from django.views.generic import CreateView
|
2020-04-30 19:07:12 +00:00
|
|
|
from django_tables2 import SingleTableView
|
2020-04-29 02:06:02 +00:00
|
|
|
|
2020-04-30 19:07:12 +00:00
|
|
|
from tournament.views import AdminMixin
|
2020-04-29 13:29:01 +00:00
|
|
|
from .forms import SignUpForm
|
2020-04-29 23:20:50 +00:00
|
|
|
from .models import TFJMUser, Document
|
2020-04-30 19:07:12 +00:00
|
|
|
from .tables import UserTable
|
2020-04-29 13:29:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CreateUserView(CreateView):
|
|
|
|
model = TFJMUser
|
|
|
|
form_class = SignUpForm
|
|
|
|
template_name = "registration/signup.html"
|
2020-04-29 23:20:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
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")
|
2020-04-30 19:07:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
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"))
|