mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-28 11:02:43 +02:00
Implement final selection
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
@ -29,8 +30,9 @@ from participation.models import Passage, Solution, Synthesis, Tournament
|
||||
from tfjm.tokens import email_validation_token
|
||||
from tfjm.views import UserMixin, UserRegistrationMixin, VolunteerMixin
|
||||
|
||||
from .forms import AddOrganizerForm, CoachRegistrationForm, HealthSheetForm, ParentalAuthorizationForm, \
|
||||
PaymentAdminForm, PaymentForm, PhotoAuthorizationForm, SignupForm, StudentRegistrationForm, UserForm, \
|
||||
from .forms import AddOrganizerForm, CoachRegistrationForm, HealthSheetForm, \
|
||||
PhotoAuthorizationFinalForm, ParentalAuthorizationForm, PaymentAdminForm, PaymentForm, \
|
||||
ParentalAuthorizationFinalForm, PhotoAuthorizationForm, SignupForm, StudentRegistrationForm, UserForm, \
|
||||
VaccineSheetForm, VolunteerRegistrationForm
|
||||
from .models import ParticipantRegistration, Payment, Registration, StudentRegistration
|
||||
from .tables import RegistrationTable
|
||||
@ -311,15 +313,27 @@ class UserUploadPhotoAuthorizationView(UserRegistrationMixin, UpdateView):
|
||||
A participant can send its photo authorization.
|
||||
"""
|
||||
model = ParticipantRegistration
|
||||
form_class = PhotoAuthorizationForm
|
||||
template_name = "registration/upload_photo_authorization.html"
|
||||
extra_context = dict(title=_("Upload photo authorization"))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
if self.object.team:
|
||||
tournament = self.object.team.participation.tournament \
|
||||
if 'final' not in self.request.path else Tournament.final_tournament()
|
||||
context["tournament"] = tournament
|
||||
return context
|
||||
|
||||
def get_form_class(self):
|
||||
return PhotoAuthorizationForm if 'final' not in self.request.path else PhotoAuthorizationFinalForm
|
||||
|
||||
@transaction.atomic
|
||||
def form_valid(self, form):
|
||||
old_instance = ParticipantRegistration.objects.get(pk=self.object.pk)
|
||||
if old_instance.photo_authorization:
|
||||
old_instance.photo_authorization.delete()
|
||||
old_instance: ParticipantRegistration = ParticipantRegistration.objects.get(pk=self.object.pk)
|
||||
old_field = old_instance.photo_authorization \
|
||||
if 'final' not in self.request.path else old_instance.photo_authorization_final
|
||||
if old_field:
|
||||
old_field.delete()
|
||||
old_instance.save()
|
||||
return super().form_valid(form)
|
||||
|
||||
@ -374,15 +388,27 @@ class UserUploadParentalAuthorizationView(UserRegistrationMixin, UpdateView):
|
||||
A participant can send its parental authorization.
|
||||
"""
|
||||
model = StudentRegistration
|
||||
form_class = ParentalAuthorizationForm
|
||||
template_name = "registration/upload_parental_authorization.html"
|
||||
extra_context = dict(title=_("Upload parental authorization"))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
if self.object.team:
|
||||
tournament = self.object.team.participation.tournament \
|
||||
if 'final' not in self.request.path else Tournament.final_tournament()
|
||||
context["tournament"] = tournament
|
||||
return context
|
||||
|
||||
def get_form_class(self):
|
||||
return ParentalAuthorizationForm if 'final' not in self.request.path else ParentalAuthorizationFinalForm
|
||||
|
||||
@transaction.atomic
|
||||
def form_valid(self, form):
|
||||
old_instance = StudentRegistration.objects.get(pk=self.object.pk)
|
||||
if old_instance.parental_authorization:
|
||||
old_instance.parental_authorization.delete()
|
||||
old_instance: StudentRegistration = StudentRegistration.objects.get(pk=self.object.pk)
|
||||
old_field = old_instance.parental_authorization \
|
||||
if 'final' not in self.request.path else old_instance.parental_authorization_final
|
||||
if old_field:
|
||||
old_field.delete()
|
||||
old_instance.save()
|
||||
return super().form_valid(form)
|
||||
|
||||
@ -666,7 +692,8 @@ class PhotoAuthorizationView(LoginRequiredMixin, View):
|
||||
path = f"media/authorization/photo/{filename}"
|
||||
if not os.path.exists(path):
|
||||
raise Http404
|
||||
student = ParticipantRegistration.objects.get(photo_authorization__endswith=filename)
|
||||
student = ParticipantRegistration.objects.get(Q(photo_authorization__endswith=filename)
|
||||
| Q(photo_authorization_final__endswith=filename))
|
||||
user = request.user
|
||||
if not (student.user == user or user.registration.is_admin or user.registration.is_volunteer and student.team
|
||||
and student.team.participation.tournament in user.registration.organized_tournaments.all()):
|
||||
@ -738,7 +765,8 @@ class ParentalAuthorizationView(LoginRequiredMixin, View):
|
||||
path = f"media/authorization/parental/{filename}"
|
||||
if not os.path.exists(path):
|
||||
raise Http404
|
||||
student = StudentRegistration.objects.get(parental_authorization__endswith=filename)
|
||||
student = StudentRegistration.objects.get(Q(parental_authorization__endswith=filename)
|
||||
| Q(parental_authorization_final__endswith=filename))
|
||||
user = request.user
|
||||
if not (student.user == user or user.registration.is_admin or user.registration.is_volunteer and student.team
|
||||
and student.team.participation.tournament in user.registration.organized_tournaments.all()):
|
||||
|
Reference in New Issue
Block a user