From 4faec03efbb942256d960be0a2a45dc5d8b44ce4 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 13 Jan 2021 16:22:26 +0100 Subject: [PATCH] Display pools table --- apps/participation/models.py | 5 +++- apps/participation/tables.py | 23 ++++++++++++++++++- .../participation/participation_detail.html | 9 ++++++++ .../participation/tournament_detail.html | 11 +++++++++ apps/participation/views.py | 3 ++- 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/apps/participation/models.py b/apps/participation/models.py index 42e93f9..af6d366 100644 --- a/apps/participation/models.py +++ b/apps/participation/models.py @@ -307,7 +307,10 @@ class Pool(models.Model): return Solution.objects.filter(participation__in=self.participations, final_solution=self.tournament.final) def __str__(self): - return repr(self) + return _("Pool {round} for tournament {tournament} with teams {teams}")\ + .format(round=self.round, + tournament=str(self.tournament), + teams=", ".join(participation.team.trigram for participation in self.participations.all())) class Meta: verbose_name = _("pool") diff --git a/apps/participation/tables.py b/apps/participation/tables.py index 2ec2dba..8f4821e 100644 --- a/apps/participation/tables.py +++ b/apps/participation/tables.py @@ -1,11 +1,12 @@ # Copyright (C) 2020 by Animath # SPDX-License-Identifier: GPL-3.0-or-later + from django.utils import formats from django.utils.text import format_lazy from django.utils.translation import gettext_lazy as _ import django_tables2 as tables -from .models import Team, Tournament +from .models import Pool, Team, Tournament # noinspection PyTypeChecker @@ -74,3 +75,23 @@ class TournamentTable(tables.Table): model = Tournament fields = ('name', 'date',) template_name = 'django_tables2/bootstrap4.html' + + +class PoolTable(tables.Table): + teams = tables.LinkColumn( + 'participation:pool_detail', + args=[tables.A('id')], + verbose_name=_("teams"), + accessor=None, + ) + + def render_teams(self, record): + return ", ".join(participation.team.trigram for participation in record.participations.all()) + + class Meta: + attrs = { + 'class': 'table table condensed table-striped', + } + model = Pool + fields = ('teams', 'round', 'tournament',) + template_name = 'django_tables2/bootstrap4.html' diff --git a/apps/participation/templates/participation/participation_detail.html b/apps/participation/templates/participation/participation_detail.html index c631b3f..1f63fa4 100644 --- a/apps/participation/templates/participation/participation_detail.html +++ b/apps/participation/templates/participation/participation_detail.html @@ -24,6 +24,15 @@ {% trans "No solution was uploaded yet." %} {% endfor %} + + {% if participation.pools.all %} +
{% trans "Pools:" %}
+
+ {% for pool in participation.pools.all %} + {{ pool }}{% if not forloop.last %}, {% endif %} + {% endfor %} +
+ {% endif %}