mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-24 21:00:33 +02:00
Add buttons to publish notes
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -26,6 +26,7 @@ from django.utils import timezone
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, DetailView, FormView, RedirectView, TemplateView, UpdateView, View
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
from django.views.generic.edit import FormMixin, ProcessFormView
|
||||
from django_tables2 import MultiTableMixin, SingleTableMixin, SingleTableView
|
||||
from magic import Magic
|
||||
@ -543,13 +544,6 @@ class TournamentDetailView(MultiTableMixin, DetailView):
|
||||
"""
|
||||
model = Tournament
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.tables = [
|
||||
ParticipationTable(self.get_object().participations.all()),
|
||||
PoolTable(self.get_object().pools.order_by('id').all()),
|
||||
]
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
tables = context['tables']
|
||||
@ -565,9 +559,17 @@ class TournamentDetailView(MultiTableMixin, DetailView):
|
||||
if note:
|
||||
notes[participation] = note
|
||||
context["notes"] = sorted(notes.items(), key=lambda x: x[1], reverse=True)
|
||||
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())
|
||||
|
||||
return context
|
||||
|
||||
def get_tables(self):
|
||||
return [
|
||||
ParticipationTable(self.object.participations.all()),
|
||||
PoolTable(self.object.pools.order_by('id').all()),
|
||||
]
|
||||
|
||||
|
||||
class TournamentPaymentsView(VolunteerMixin, SingleTableMixin, DetailView):
|
||||
"""
|
||||
@ -631,6 +633,34 @@ class TournamentExportCSVView(VolunteerMixin, DetailView):
|
||||
return resp
|
||||
|
||||
|
||||
class TournamentPublishNotesView(VolunteerMixin, SingleObjectMixin, RedirectView):
|
||||
"""
|
||||
Publish notes of a tournament for a given round.
|
||||
"""
|
||||
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()
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
if int(kwargs["round"]) not in (1, 2):
|
||||
raise Http404
|
||||
|
||||
tournament = Tournament.objects.get(pk=kwargs["pk"])
|
||||
tournament.pools.filter(round=kwargs["round"]).update(results_available=True)
|
||||
messages.success(request, _("Notes published!"))
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
return reverse_lazy("participation:tournament_detail", args=(kwargs['pk'],))
|
||||
|
||||
|
||||
class SolutionUploadView(LoginRequiredMixin, FormView):
|
||||
template_name = "participation/upload_solution.html"
|
||||
form_class = SolutionForm
|
||||
|
Reference in New Issue
Block a user