1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-24 03:02:23 +00:00

Display pools table

This commit is contained in:
Yohann D'ANELLO 2021-01-13 16:22:26 +01:00
parent 170326d503
commit 4faec03efb
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
5 changed files with 48 additions and 3 deletions

View File

@ -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")

View File

@ -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'

View File

@ -24,6 +24,15 @@
{% trans "No solution was uploaded yet." %}
{% endfor %}
</dd>
{% if participation.pools.all %}
<dt class="col-sm-2">{% trans "Pools:" %}</dt>
<dd class="col-sm-10">
{% for pool in participation.pools.all %}
<a href="{{ pool.get_absolute_url }}" data-turbolinks="false">{{ pool }}{% if not forloop.last %}, {% endif %}</a>
{% endfor %}
</dd>
{% endif %}
</dl>
</div>
<div class="card-footer text-center">

View File

@ -60,4 +60,15 @@
<div id="teams_table">
{% render_table teams %}
</div>
<hr>
<h3>{% trans "Pools" %}</h3>
<div id="pools_table">
{% render_table pools %}
</div>
{% if user.registration.is_admin %}
<a class="btn btn-block btn-success" href="#">{% trans "Add new pool" %}</a>
{% endif %}
{% endblock %}

View File

@ -26,7 +26,7 @@ from tfjm.views import AdminMixin
from .forms import JoinTeamForm, ParticipationForm, RequestValidationForm, SolutionForm, TeamForm, TournamentForm, \
ValidateParticipationForm
from .models import Participation, Team, Tournament, Solution
from .tables import TeamTable, TournamentTable, ParticipationTable
from .tables import TeamTable, TournamentTable, ParticipationTable, PoolTable
class CreateTeamView(LoginRequiredMixin, CreateView):
@ -434,6 +434,7 @@ class TournamentDetailView(DetailView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["teams"] = ParticipationTable(self.object.participations.all())
context["pools"] = PoolTable(self.object.pools.all())
return context