mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-08-04 15:31:07 +02:00
Upload syntheses
This commit is contained in:
@@ -24,8 +24,8 @@ from tfjm.matrix import Matrix
|
||||
from tfjm.views import AdminMixin
|
||||
|
||||
from .forms import JoinTeamForm, ParticipationForm, PassageForm, PoolForm, PoolTeamsForm, RequestValidationForm, \
|
||||
SolutionForm, TeamForm, TournamentForm, ValidateParticipationForm
|
||||
from .models import Participation, Passage, Pool, Team, Tournament, Solution
|
||||
TeamForm, TournamentForm, ValidateParticipationForm, SolutionForm, SynthesisForm
|
||||
from .models import Participation, Passage, Pool, Team, Tournament, Solution, Synthesis
|
||||
from .tables import TeamTable, TournamentTable, ParticipationTable, PoolTable
|
||||
|
||||
|
||||
@@ -460,6 +460,7 @@ class SolutionUploadView(LoginRequiredMixin, FormView):
|
||||
for sol in Solution.objects.filter(participation=self.participation,
|
||||
problem=form_sol.problem,
|
||||
final_solution=self.participation.final).all():
|
||||
sol.file.delete()
|
||||
sol.delete()
|
||||
form_sol.participation = self.participation
|
||||
form_sol.final = self.participation.final
|
||||
@@ -475,7 +476,7 @@ class PoolCreateView(AdminMixin, CreateView):
|
||||
form_class = PoolForm
|
||||
|
||||
|
||||
class PoolDetailView(AdminMixin, DetailView):
|
||||
class PoolDetailView(LoginRequiredMixin, DetailView):
|
||||
model = Pool
|
||||
|
||||
|
||||
@@ -509,7 +510,7 @@ class PassageCreateView(AdminMixin, CreateView):
|
||||
return form
|
||||
|
||||
|
||||
class PassageDetailView(AdminMixin, DetailView):
|
||||
class PassageDetailView(LoginRequiredMixin, DetailView):
|
||||
model = Passage
|
||||
|
||||
|
||||
@@ -517,3 +518,36 @@ class PassageUpdateView(AdminMixin, UpdateView):
|
||||
model = Passage
|
||||
form_class = PassageForm
|
||||
|
||||
|
||||
class SynthesisUploadView(LoginRequiredMixin, FormView):
|
||||
template_name = "participation/upload_synthesis.html"
|
||||
form_class = SynthesisForm
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
qs = Passage.objects.filter(pk=self.kwargs["pk"])
|
||||
if not qs.exists():
|
||||
raise Http404
|
||||
self.participation = self.request.user.registration.team.participation
|
||||
self.passage = qs.get()
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
"""
|
||||
When a solution is submitted, it replaces a previous solution if existing,
|
||||
otherwise it creates a new solution.
|
||||
It is discriminating whenever the team is selected for the final tournament or not.
|
||||
"""
|
||||
form_syn = form.instance
|
||||
# Drop previous solution if existing
|
||||
for syn in Synthesis.objects.filter(participation=self.participation,
|
||||
passage=self.passage,
|
||||
type=form_syn.type).all():
|
||||
syn.file.delete()
|
||||
syn.delete()
|
||||
form_syn.participation = self.participation
|
||||
form_syn.passage = self.passage
|
||||
form_syn.save()
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("participation:passage_detail", args=(self.passage.pk,))
|
||||
|
Reference in New Issue
Block a user