mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-07-04 07:32:18 +02:00
Upload solution is working
This commit is contained in:
@ -9,7 +9,7 @@ from django.contrib.sites.models import Site
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.mail import send_mail
|
||||
from django.db import transaction
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse, Http404
|
||||
from django.shortcuts import redirect
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse_lazy
|
||||
@ -23,9 +23,9 @@ from tfjm.lists import get_sympa_client
|
||||
from tfjm.matrix import Matrix
|
||||
from tfjm.views import AdminMixin
|
||||
|
||||
from .forms import JoinTeamForm, ParticipationForm, RequestValidationForm, TeamForm, ValidateParticipationForm, \
|
||||
TournamentForm
|
||||
from .models import Participation, Team, Tournament
|
||||
from .forms import JoinTeamForm, ParticipationForm, RequestValidationForm, SolutionForm, TeamForm, TournamentForm, \
|
||||
ValidateParticipationForm
|
||||
from .models import Participation, Team, Tournament, Solution
|
||||
from .tables import TeamTable, TournamentTable, ParticipationTable
|
||||
|
||||
|
||||
@ -435,3 +435,36 @@ class TournamentDetailView(DetailView):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["teams"] = ParticipationTable(self.object.participations.all())
|
||||
return context
|
||||
|
||||
|
||||
class SolutionUploadView(LoginRequiredMixin, FormView):
|
||||
template_name = "participation/upload_solution.html"
|
||||
form_class = SolutionForm
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
qs = Participation.objects.filter(pk=self.kwargs["pk"])
|
||||
if not qs.exists():
|
||||
raise Http404
|
||||
self.participation = 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_sol = form.instance
|
||||
# Drop previous solution if existing
|
||||
Solution.objects.filter(
|
||||
participation=self.participation,
|
||||
problem=form_sol.problem,
|
||||
final_solution=self.participation.final,
|
||||
).delete()
|
||||
form_sol.participation = self.participation
|
||||
form_sol.final = self.participation.final
|
||||
form_sol.save()
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("participation:participation_detail", args=(self.participation.pk,))
|
||||
|
Reference in New Issue
Block a user