1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-11-26 14:07:08 +00:00
plateforme-tfjm2/apps/tournament/tables.py
2020-05-11 14:08:19 +02:00

165 lines
4.2 KiB
Python

import django_tables2 as tables
from django.urls import reverse_lazy
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _
from django_tables2 import A
from member.models import Solution, Synthesis
from .models import Tournament, Team, Pool
class TournamentTable(tables.Table):
"""
List all tournaments.
"""
name = tables.LinkColumn(
"tournament:detail",
args=[A("pk")],
)
date_start = tables.Column(
verbose_name=_("dates").capitalize(),
)
def render_date_start(self, record):
return _("From {start:%b %d %Y} to {end:%b %d %Y}").format(start=record.date_start, end=record.date_end)
class Meta:
model = Tournament
fields = ("name", "date_start", "date_inscription", "date_solutions", "size", )
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
order_by = ('date_start', 'name',)
class TeamTable(tables.Table):
"""
Table of some teams. Can be filtered with a queryset (for example, teams of a tournament)
"""
name = tables.LinkColumn(
"tournament:team_detail",
args=[A("pk")],
)
class Meta:
model = Team
fields = ("name", "trigram", "validation_status", )
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
order_by = ('-validation_status', 'trigram',)
class SolutionTable(tables.Table):
"""
Display a table of some solutions.
"""
team = tables.LinkColumn(
"tournament:team_detail",
args=[A("team.pk")],
)
tournament = tables.LinkColumn(
"tournament:detail",
args=[A("tournament.pk")],
accessor=A("tournament"),
order_by=("team__tournament__date_start", "team__tournament__name",),
verbose_name=_("Tournament"),
)
file = tables.LinkColumn(
"document",
args=[A("file")],
attrs={
"a": {
"data-turbolinks": "false",
}
}
)
def render_file(self):
return _("Download")
class Meta:
model = Solution
fields = ("team", "tournament", "problem", "uploaded_at", "file", )
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
class SynthesisTable(tables.Table):
"""
Display a table of some syntheses.
"""
team = tables.LinkColumn(
"tournament:team_detail",
args=[A("team.pk")],
)
tournament = tables.LinkColumn(
"tournament:detail",
args=[A("tournament.pk")],
accessor=A("tournament"),
order_by=("team__tournament__date_start", "team__tournament__name",),
verbose_name=_("tournament"),
)
file = tables.LinkColumn(
"document",
args=[A("file")],
attrs={
"a": {
"data-turbolinks": "false",
}
}
)
def render_file(self):
return _("Download")
class Meta:
model = Synthesis
fields = ("team", "tournament", "round", "source", "uploaded_at", "file", )
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
class PoolTable(tables.Table):
"""
Display a table of some pools.
"""
problems = tables.Column(
verbose_name=_("Problems"),
orderable=False,
)
tournament = tables.LinkColumn(
"tournament:detail",
args=[A("tournament.pk")],
verbose_name=_("Tournament"),
order_by=("teams__tournament__date_start", "teams__tournament__name",),
)
def render_teams(self, record, value):
return format_html('<a href="{url}">{trigrams}</a>',
url=reverse_lazy('tournament:pool_detail', args=(record.pk,)),
trigrams=", ".join(team.trigram for team in value.all()))
def render_problems(self, value):
return ", ".join([str(pb) for pb in value])
class Meta:
model = Pool
fields = ("teams", "tournament", "problems", "round", )
attrs = {
'class': 'table table-condensed table-striped table-hover'
}