From 4d83664c0dc1696d8be89fb787c4d430db785206 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 13 Jan 2021 17:00:50 +0100 Subject: [PATCH] Register pools --- apps/participation/forms.py | 8 +++++++- .../migrations/0008_auto_20210113_1700.py | 18 +++++++++++++++++ apps/participation/models.py | 7 +++++++ apps/participation/tables.py | 7 ++++--- .../participation/participation_detail.html | 1 - .../templates/participation/pool_detail.html | 1 + .../templates/participation/pool_form.html | 13 ++++++++++++ .../participation/tournament_detail.html | 19 +++++++++++++++++- apps/participation/urls.py | 9 ++++++--- apps/participation/views.py | 20 ++++++++++++++++--- 10 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 apps/participation/migrations/0008_auto_20210113_1700.py create mode 100644 apps/participation/templates/participation/pool_detail.html create mode 100644 apps/participation/templates/participation/pool_form.html diff --git a/apps/participation/forms.py b/apps/participation/forms.py index 8f7f649..0a7b4cc 100644 --- a/apps/participation/forms.py +++ b/apps/participation/forms.py @@ -9,7 +9,7 @@ from django.core.exceptions import ValidationError from django.utils import formats from django.utils.translation import gettext_lazy as _ -from .models import Participation, Team, Tournament, Solution +from .models import Participation, Team, Tournament, Solution, Pool class TeamForm(forms.ModelForm): @@ -123,3 +123,9 @@ class SolutionForm(forms.ModelForm): class Meta: model = Solution fields = ('problem', 'file',) + + +class PoolForm(forms.ModelForm): + class Meta: + model = Pool + fields = ('tournament', 'round', 'juries',) diff --git a/apps/participation/migrations/0008_auto_20210113_1700.py b/apps/participation/migrations/0008_auto_20210113_1700.py new file mode 100644 index 0000000..9beea1c --- /dev/null +++ b/apps/participation/migrations/0008_auto_20210113_1700.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.11 on 2021-01-13 16:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('participation', '0007_auto_20210112_1801'), + ] + + operations = [ + migrations.AlterField( + model_name='pool', + name='round', + field=models.PositiveSmallIntegerField(choices=[(1, 'Round 1'), (2, 'Round 2')], verbose_name='round'), + ), + ] diff --git a/apps/participation/models.py b/apps/participation/models.py index af6d366..79303b2 100644 --- a/apps/participation/models.py +++ b/apps/participation/models.py @@ -288,6 +288,10 @@ class Pool(models.Model): round = models.PositiveSmallIntegerField( verbose_name=_("round"), + choices=[ + (1, format_lazy(_("Round {round}"), round=1)), + (2, format_lazy(_("Round {round}"), round=2)), + ] ) participations = models.ManyToManyField( @@ -306,6 +310,9 @@ class Pool(models.Model): def solutions(self): return Solution.objects.filter(participation__in=self.participations, final_solution=self.tournament.final) + def get_absolute_url(self): + return reverse_lazy("participation:pool_detail", args=(self.pk,)) + def __str__(self): return _("Pool {round} for tournament {tournament} with teams {teams}")\ .format(round=self.round, diff --git a/apps/participation/tables.py b/apps/participation/tables.py index 8f4821e..8cbb34d 100644 --- a/apps/participation/tables.py +++ b/apps/participation/tables.py @@ -81,12 +81,13 @@ class PoolTable(tables.Table): teams = tables.LinkColumn( 'participation:pool_detail', args=[tables.A('id')], - verbose_name=_("teams"), - accessor=None, + verbose_name=_("teams").capitalize, + empty_values=(), ) def render_teams(self, record): - return ", ".join(participation.team.trigram for participation in record.participations.all()) + return ", ".join(participation.team.trigram for participation in record.participations.all()) \ + or _("No defined team") class Meta: attrs = { diff --git a/apps/participation/templates/participation/participation_detail.html b/apps/participation/templates/participation/participation_detail.html index 1f63fa4..aa57347 100644 --- a/apps/participation/templates/participation/participation_detail.html +++ b/apps/participation/templates/participation/participation_detail.html @@ -50,7 +50,6 @@ {% endblock %} diff --git a/apps/participation/urls.py b/apps/participation/urls.py index f67deec..e04784e 100644 --- a/apps/participation/urls.py +++ b/apps/participation/urls.py @@ -5,9 +5,9 @@ from django.urls import path from django.views.generic import TemplateView from .views import CreateTeamView, JoinTeamView, \ - MyParticipationDetailView, MyTeamDetailView, ParticipationDetailView, TeamAuthorizationsView, \ - TeamDetailView, TeamLeaveView, TeamListView, TeamUpdateView, TournamentCreateView, TournamentDetailView, \ - TournamentListView, TournamentUpdateView, SolutionUploadView + MyParticipationDetailView, MyTeamDetailView, ParticipationDetailView, PoolCreateView, PoolDetailView, \ + PoolUpdateView, TeamAuthorizationsView, TeamDetailView, TeamLeaveView, TeamListView, TeamUpdateView, \ + TournamentCreateView, TournamentDetailView, TournamentListView, TournamentUpdateView, SolutionUploadView app_name = "participation" @@ -28,5 +28,8 @@ urlpatterns = [ path("tournament/create/", TournamentCreateView.as_view(), name="tournament_create"), path("tournament//", TournamentDetailView.as_view(), name="tournament_detail"), path("tournament//update/", TournamentUpdateView.as_view(), name="tournament_update"), + path("pools/create/", PoolCreateView.as_view(), name="pool_create"), + path("pools//", PoolDetailView.as_view(), name="pool_detail"), + path("pools//update/", PoolUpdateView.as_view(), name="pool_update"), path("chat/", TemplateView.as_view(template_name="participation/chat.html"), name="chat") ] diff --git a/apps/participation/views.py b/apps/participation/views.py index af06527..f5731b6 100644 --- a/apps/participation/views.py +++ b/apps/participation/views.py @@ -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, SolutionForm, TeamForm, TournamentForm, \ - ValidateParticipationForm -from .models import Participation, Team, Tournament, Solution +from .forms import JoinTeamForm, ParticipationForm, PoolForm, RequestValidationForm, SolutionForm, TeamForm,\ + TournamentForm, ValidateParticipationForm +from .models import Participation, Team, Tournament, Solution, Pool from .tables import TeamTable, TournamentTable, ParticipationTable, PoolTable @@ -468,3 +468,17 @@ class SolutionUploadView(LoginRequiredMixin, FormView): def get_success_url(self): return reverse_lazy("participation:participation_detail", args=(self.participation.pk,)) + + +class PoolCreateView(AdminMixin, CreateView): + model = Pool + form_class = PoolForm + + +class PoolDetailView(AdminMixin, DetailView): + model = Pool + + +class PoolUpdateView(AdminMixin, UpdateView): + model = Pool + form_class = PoolForm