Don't upload solutions or syntheses after the deadline, if an existing file was previously sent

This commit is contained in:
Yohann D'ANELLO 2021-01-19 00:11:52 +01:00
parent a55eea7c10
commit 5a865efd18
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 23 additions and 7 deletions

View File

@ -13,6 +13,7 @@ from django.http import Http404, HttpResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils import timezone
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, DetailView, FormView, RedirectView, TemplateView, UpdateView from django.views.generic import CreateView, DetailView, FormView, RedirectView, TemplateView, UpdateView
from django.views.generic.edit import FormMixin, ProcessFormView from django.views.generic.edit import FormMixin, ProcessFormView
@ -505,10 +506,17 @@ class SolutionUploadView(LoginRequiredMixin, FormView):
It is discriminating whenever the team is selected for the final tournament or not. It is discriminating whenever the team is selected for the final tournament or not.
""" """
form_sol = form.instance form_sol = form.instance
sol_qs = Solution.objects.filter(participation=self.participation,
problem=form_sol.problem,
final_solution=self.participation.final)
tournament = Tournament.final_tournament() if self.participation.final else self.participation.final
if timezone.now() > tournament.solution_limit and sol_qs.exists():
form.add_error(None, _("You can't upload a solution after the deadline."))
return self.form_invalid(form)
# Drop previous solution if existing # Drop previous solution if existing
for sol in Solution.objects.filter(participation=self.participation, for sol in sol_qs.all():
problem=form_sol.problem,
final_solution=self.participation.final).all():
sol.file.delete() sol.file.delete()
sol.delete() sol.delete()
form_sol.participation = self.participation form_sol.participation = self.participation
@ -605,7 +613,7 @@ class PassageCreateView(VolunteerMixin, CreateView):
def get_form(self, form_class=None): def get_form(self, form_class=None):
form = super().get_form(form_class) form = super().get_form(form_class)
form.instance.pool = self.pool form.instance.pool = self.pool
form.fields["defender"].queryset = self.pool.participations.all() fSynthesisorm.fields["defender"].queryset = self.pool.participations.all()
form.fields["opponent"].queryset = self.pool.participations.all() form.fields["opponent"].queryset = self.pool.participations.all()
form.fields["reporter"].queryset = self.pool.participations.all() form.fields["reporter"].queryset = self.pool.participations.all()
return form return form
@ -677,10 +685,18 @@ class SynthesisUploadView(LoginRequiredMixin, FormView):
It is discriminating whenever the team is selected for the final tournament or not. It is discriminating whenever the team is selected for the final tournament or not.
""" """
form_syn = form.instance form_syn = form.instance
syn_qs = Synthesis.objects.filter(participation=self.participation,
passage=self.passage,
type=form_syn.type).all()
deadline = self.passage.pool.tournament.syntheses_first_phase_limit if self.passage.pool.round == 1 \
else self.passage.pool.tournament.syntheses_second_phase_limit
if syn_qs.exists() and timezone.now() > deadline:
form.add_error(None, _("You can't upload a synthesis after the deadline."))
return self.form_invalid(form)
# Drop previous solution if existing # Drop previous solution if existing
for syn in Synthesis.objects.filter(participation=self.participation, for syn in syn_qs.all():
passage=self.passage,
type=form_syn.type).all():
syn.file.delete() syn.file.delete()
syn.delete() syn.delete()
form_syn.participation = self.participation form_syn.participation = self.participation