1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-29 23:11:12 +02:00

Implement final selection

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2024-04-07 11:40:58 +02:00
parent 7732a737bb
commit 1493df0078
15 changed files with 657 additions and 310 deletions

View File

@ -399,6 +399,7 @@ class TeamAuthorizationsView(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs):
if 'team_id' in kwargs:
team = Team.objects.get(pk=kwargs["team_id"])
tournament = team.participation.tournament
teams = [team]
filename = _("Authorizations of team {trigram}.zip").format(trigram=team.trigram)
else:
@ -415,21 +416,25 @@ class TeamAuthorizationsView(LoginRequiredMixin, View):
for participant in team.participants.all():
user_prefix = f"{team_prefix}{participant.user.first_name} {participant.user.last_name}/"
if participant.photo_authorization \
and participant.photo_authorization.storage.exists(participant.photo_authorization.path):
mime_type = magic.from_file("media/" + participant.photo_authorization.name)
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
zf.write("media/" + participant.photo_authorization.name,
user_prefix + _("Photo authorization of {participant}.{ext}")
.format(participant=str(participant), ext=ext))
if 'team_id' in kwargs or not tournament.final:
# Don't include the photo authorization and the parental authorization of the regional tournament
# in the final authorizations
if participant.photo_authorization \
and participant.photo_authorization.storage.exists(participant.photo_authorization.path):
mime_type = magic.from_file("media/" + participant.photo_authorization.name)
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
zf.write("media/" + participant.photo_authorization.name,
user_prefix + _("Photo authorization of {participant}.{ext}")
.format(participant=str(participant), ext=ext))
if participant.is_student and participant.parental_authorization \
and participant.parental_authorization.storage.exists(participant.parental_authorization.path):
mime_type = magic.from_file("media/" + participant.parental_authorization.name)
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
zf.write("media/" + participant.parental_authorization.name,
user_prefix + _("Parental authorization of {participant}.{ext}")
.format(participant=str(participant), ext=ext))
if participant.is_student and participant.parental_authorization \
and participant.parental_authorization.storage.exists(
participant.parental_authorization.path):
mime_type = magic.from_file("media/" + participant.parental_authorization.name)
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
zf.write("media/" + participant.parental_authorization.name,
user_prefix + _("Parental authorization of {participant}.{ext}")
.format(participant=str(participant), ext=ext))
if participant.is_student and participant.health_sheet \
and participant.health_sheet.storage.exists(participant.health_sheet.path):
@ -447,6 +452,26 @@ class TeamAuthorizationsView(LoginRequiredMixin, View):
user_prefix + _("Vaccine sheet of {participant}.{ext}")
.format(participant=str(participant), ext=ext))
if 'team_id' in kwargs or tournament.final:
# Don't include final authorizations in the regional authorizations
if participant.photo_authorization_final \
and participant.photo_authorization_final.storage.exists(
participant.photo_authorization_final.path):
mime_type = magic.from_file("media/" + participant.photo_authorization_final.name)
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
zf.write("media/" + participant.photo_authorization_final.name,
user_prefix + _("Photo authorization of {participant} (final).{ext}")
.format(participant=str(participant), ext=ext))
if participant.is_student and participant.parental_authorization_final \
and participant.parental_authorization_final.storage.exists(
participant.parental_authorization_final.path):
mime_type = magic.from_file("media/" + participant.parental_authorization_final.name)
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
zf.write("media/" + participant.parental_authorization_final.name,
user_prefix + _("Parental authorization of {participant} (final).{ext}")
.format(participant=str(participant), ext=ext))
if team.motivation_letter and team.motivation_letter.storage.exists(team.motivation_letter.path):
mime_type = magic.from_file("media/" + team.motivation_letter.name)
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
@ -591,10 +616,15 @@ class TournamentDetailView(MultiTableMixin, DetailView):
or (self.request.user.is_authenticated and self.request.user.registration.is_volunteer))
if note:
notes[participation] = note
context["notes"] = sorted(notes.items(), key=lambda x: x[1], reverse=True)
sorted_notes = sorted(notes.items(), key=lambda x: x[1], reverse=True)
context["notes"] = sorted_notes
context["available_notes_1"] = all(pool.results_available for pool in self.object.pools.filter(round=1).all())
context["available_notes_2"] = all(pool.results_available for pool in self.object.pools.filter(round=2).all())
if not self.object.final and notes and self.request.user.registration.is_volunteer:
context["team_selectable_for_final"] = next(participation for participation, _note in sorted_notes
if not participation.final)
return context
def get_tables(self):
@ -625,8 +655,11 @@ class TournamentPaymentsView(VolunteerMixin, SingleTableMixin, DetailView):
return super().dispatch(request, *args, **kwargs)
def get_table_data(self):
return Payment.objects.filter(registrations__team__participation__tournament=self.get_object()) \
.annotate(team_id=F('registrations__team')).order_by('-valid', 'registrations__team__trigram') \
if self.object.final:
payments = Payment.objects.filter(final=True)
else:
payments = Payment.objects.filter(registrations__team__participation__tournament=self.get_object())
return payments.annotate(team_id=F('registrations__team')).order_by('-valid', 'registrations__team__trigram') \
.distinct().all()
@ -795,6 +828,30 @@ class TournamentHarmonizeNoteView(VolunteerMixin, DetailView):
return redirect(reverse_lazy("participation:tournament_harmonize", args=(tournament.pk, kwargs['round'],)))
class SelectTeamFinalView(VolunteerMixin, DetailView):
model = Tournament
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return self.handle_no_permission()
tournament = self.get_object()
reg = request.user.registration
if not reg.is_admin and (not reg.is_volunteer or tournament not in reg.organized_tournaments.all()):
return self.handle_no_permission()
participation_qs = tournament.participations.filter(pk=self.kwargs["participation_id"])
if not participation_qs.exists():
raise Http404
self.participation = participation_qs.get()
return super().dispatch(request, *args, **kwargs)
@transaction.atomic
def get(self, request, *args, **kwargs):
tournament = self.get_object()
self.participation.final = True
self.participation.save()
return redirect(reverse_lazy("participation:tournament_detail", args=(tournament.pk,)))
class SolutionUploadView(LoginRequiredMixin, FormView):
template_name = "participation/upload_solution.html"
form_class = SolutionForm