From 0f65bc4561af176b700e82985455bcf12a5ebd14 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 1 Jan 2021 12:11:09 +0100 Subject: [PATCH] Display details about tournaments --- apps/participation/forms.py | 4 ++ .../migrations/0004_tournament_price.py | 18 ++++++ .../migrations/0005_auto_20210101_1149.py | 24 +++++++ apps/participation/models.py | 15 +++++ apps/participation/tables.py | 13 +--- .../participation/tournament_detail.html | 63 +++++++++++++++++++ .../participation/tournament_form.html | 6 +- apps/participation/views.py | 9 ++- apps/registration/templatetags/getconfig.py | 14 +++++ 9 files changed, 152 insertions(+), 14 deletions(-) create mode 100644 apps/participation/migrations/0004_tournament_price.py create mode 100644 apps/participation/migrations/0005_auto_20210101_1149.py create mode 100644 apps/participation/templates/participation/tournament_detail.html create mode 100644 apps/registration/templatetags/getconfig.py diff --git a/apps/participation/forms.py b/apps/participation/forms.py index cce1358..1b9a974 100644 --- a/apps/participation/forms.py +++ b/apps/participation/forms.py @@ -101,8 +101,12 @@ class TournamentForm(forms.ModelForm): format=formats.get_format_lazy(format_type="DATETIME_INPUT_FORMATS", use_l10n=True)[0]) self.fields["solution_limit"].widget = DateTimePickerInput( format=formats.get_format_lazy(format_type="DATETIME_INPUT_FORMATS", use_l10n=True)[0]) + self.fields["solutions_draw"].widget = DateTimePickerInput( + format=formats.get_format_lazy(format_type="DATETIME_INPUT_FORMATS", use_l10n=True)[0]) self.fields["syntheses_first_phase_limit"].widget = DateTimePickerInput( format=formats.get_format_lazy(format_type="DATETIME_INPUT_FORMATS", use_l10n=True)[0]) + self.fields["solutions_available_second_phase"].widget = DateTimePickerInput( + format=formats.get_format_lazy(format_type="DATETIME_INPUT_FORMATS", use_l10n=True)[0]) self.fields["syntheses_second_phase_limit"].widget = DateTimePickerInput( format=formats.get_format_lazy(format_type="DATETIME_INPUT_FORMATS", use_l10n=True)[0]) diff --git a/apps/participation/migrations/0004_tournament_price.py b/apps/participation/migrations/0004_tournament_price.py new file mode 100644 index 0000000..d6ad916 --- /dev/null +++ b/apps/participation/migrations/0004_tournament_price.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.11 on 2021-01-01 10:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('participation', '0003_tournament_max_teams'), + ] + + operations = [ + migrations.AddField( + model_name='tournament', + name='price', + field=models.PositiveSmallIntegerField(default=21, verbose_name='price'), + ), + ] diff --git a/apps/participation/migrations/0005_auto_20210101_1149.py b/apps/participation/migrations/0005_auto_20210101_1149.py new file mode 100644 index 0000000..909c5fc --- /dev/null +++ b/apps/participation/migrations/0005_auto_20210101_1149.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.11 on 2021-01-01 10:49 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('participation', '0004_tournament_price'), + ] + + operations = [ + migrations.AddField( + model_name='tournament', + name='solutions_available_second_phase', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='date when the solutions for the second round become available'), + ), + migrations.AddField( + model_name='tournament', + name='solutions_draw', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='random draw for solutions'), + ), + ] diff --git a/apps/participation/models.py b/apps/participation/models.py index f81dcda..c405c3d 100644 --- a/apps/participation/models.py +++ b/apps/participation/models.py @@ -143,6 +143,11 @@ class Tournament(models.Model): default=9, ) + price = models.PositiveSmallIntegerField( + verbose_name=_("price"), + default=21, + ) + inscription_limit = models.DateTimeField( verbose_name=_("limit date for registrations"), default=timezone.now, @@ -153,11 +158,21 @@ class Tournament(models.Model): default=timezone.now, ) + solutions_draw = models.DateTimeField( + verbose_name=_("random draw for solutions"), + default=timezone.now, + ) + syntheses_first_phase_limit = models.DateTimeField( verbose_name=_("limit date to upload the syntheses for the first phase"), default=timezone.now, ) + solutions_available_second_phase = models.DateTimeField( + verbose_name=_("date when the solutions for the second round become available"), + default=timezone.now, + ) + syntheses_second_phase_limit = models.DateTimeField( verbose_name=_("limit date to upload the syntheses for the second phase"), default=timezone.now, diff --git a/apps/participation/tables.py b/apps/participation/tables.py index 11d517d..e3ebd0e 100644 --- a/apps/participation/tables.py +++ b/apps/participation/tables.py @@ -16,17 +16,12 @@ class TeamTable(tables.Table): verbose_name=lambda: _("name").capitalize(), ) - problem = tables.Column( - accessor="participation__problem", - verbose_name=lambda: _("problem number").capitalize(), - ) - class Meta: attrs = { 'class': 'table table condensed table-striped', } model = Team - fields = ('name', 'trigram', 'problem',) + fields = ('name', 'trigram',) template_name = 'django_tables2/bootstrap4.html' @@ -44,16 +39,12 @@ class ParticipationTable(tables.Table): accessor="team__trigram", ) - problem = tables.Column( - verbose_name=lambda: _("problem number").capitalize(), - ) - class Meta: attrs = { 'class': 'table table condensed table-striped', } model = Team - fields = ('name', 'trigram', 'problem',) + fields = ('name', 'trigram', 'valid',) template_name = 'django_tables2/bootstrap4.html' diff --git a/apps/participation/templates/participation/tournament_detail.html b/apps/participation/templates/participation/tournament_detail.html new file mode 100644 index 0000000..81523c8 --- /dev/null +++ b/apps/participation/templates/participation/tournament_detail.html @@ -0,0 +1,63 @@ +{% extends "base.html" %} + +{% load getconfig i18n django_tables2 %} + +{% block content %} +
+
+

{{ tournament.name }}

+
+
+
+
{% trans 'organizers'|capfirst %}
+
{{ tournament.organizers.all|join:", " }}
+ +
{% trans 'size'|capfirst %}
+
{{ tournament.max_teams }}
+ +
{% trans 'place'|capfirst %}
+
{{ tournament.place }}
+ +
{% trans 'price'|capfirst %}
+
{% if tournament.price %}{{ tournament.price }} €{% else %}{% trans "Free" %}{% endif %}
+ +
{% trans 'dates'|capfirst %}
+
{% trans "From" %} {{ tournament.date_start }} {% trans "to" %} {{ tournament.date_end }}
+ +
{% trans 'date of registration closing'|capfirst %}
+
{{ tournament.inscription_limit }}
+ +
{% trans 'date of maximal solution submission'|capfirst %}
+
{{ tournament.solution_limit }}
+ +
{% trans 'date of the random draw'|capfirst %}
+
{{ tournament.solutions_draw }}
+ +
{% trans 'date of maximal syntheses submission for the first round'|capfirst %}
+
{{ tournament.syntheses_first_phase_limit }}
+ +
{% trans 'date when solutions of round 2 are available'|capfirst %}
+
{{ tournament.solutions_available_second_phase }}
+ +
{% trans 'date of maximal syntheses submission for the second round'|capfirst %}
+
{{ tournament.syntheses_second_phase_limit }}
+ +
{% trans 'description'|capfirst %}
+
{{ tournament.description }}
+
+
+ + {% if user.registration.isadmin or user.registration in tournament.organizers.all %} + + {% endif %} +
+ +
+ +

{% trans "Teams" %}

+
+ {% render_table teams %} +
+{% endblock %} diff --git a/apps/participation/templates/participation/tournament_form.html b/apps/participation/templates/participation/tournament_form.html index 1c93537..e436656 100644 --- a/apps/participation/templates/participation/tournament_form.html +++ b/apps/participation/templates/participation/tournament_form.html @@ -8,6 +8,10 @@ {% csrf_token %} {{ form|crispy }} - + {% if object.pk %} + + {% else %} + + {% endif %} {% endblock content %} diff --git a/apps/participation/views.py b/apps/participation/views.py index 6f00049..fd6e5f8 100644 --- a/apps/participation/views.py +++ b/apps/participation/views.py @@ -26,7 +26,7 @@ from tfjm.views import AdminMixin from .forms import JoinTeamForm, ParticipationForm, RequestValidationForm, TeamForm, ValidateParticipationForm, \ TournamentForm from .models import Participation, Team, Tournament -from .tables import TeamTable, TournamentTable +from .tables import TeamTable, TournamentTable, ParticipationTable class CreateTeamView(LoginRequiredMixin, CreateView): @@ -129,7 +129,7 @@ class TeamListView(AdminMixin, SingleTableView): """ model = Team table_class = TeamTable - ordering = ('participation__problem', 'trigram',) + ordering = ('trigram',) class MyTeamDetailView(LoginRequiredMixin, RedirectView): @@ -430,3 +430,8 @@ class TournamentDetailView(DetailView): Display tournament detail. """ model = Tournament + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["teams"] = ParticipationTable(self.object.participations.all()) + return context diff --git a/apps/registration/templatetags/getconfig.py b/apps/registration/templatetags/getconfig.py new file mode 100644 index 0000000..e0ce73a --- /dev/null +++ b/apps/registration/templatetags/getconfig.py @@ -0,0 +1,14 @@ +# Copyright (C) 2020 by Animath +# SPDX-License-Identifier: GPL-3.0-or-later + +import os + +from django import template + + +def get_env(key: str) -> str: + return os.getenv(key) + + +register = template.Library() +register.filter("get_env", get_env)