1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-11-30 01:33:01 +00:00
plateforme-tfjm2/apps/tournament/tables.py

165 lines
4.2 KiB
Python
Raw Normal View History

2020-04-29 14:26:52 +00:00
import django_tables2 as tables
2020-05-05 04:07:49 +00:00
from django.urls import reverse_lazy
2020-05-06 12:39:03 +00:00
from django.utils.html import format_html
2020-05-05 22:15:46 +00:00
from django.utils.translation import gettext_lazy as _
2020-04-29 14:59:59 +00:00
from django_tables2 import A
2020-04-29 14:26:52 +00:00
2020-05-04 22:11:38 +00:00
from member.models import Solution, Synthesis
2020-05-05 02:45:38 +00:00
from .models import Tournament, Team, Pool
2020-04-29 14:26:52 +00:00
class TournamentTable(tables.Table):
2020-05-11 12:08:19 +00:00
"""
List all tournaments.
"""
2020-04-29 14:59:59 +00:00
name = tables.LinkColumn(
"tournament:detail",
args=[A("pk")],
)
2020-04-29 14:26:52 +00:00
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'
}
2020-05-05 14:04:53 +00:00
order_by = ('date_start', 'name',)
2020-04-29 14:59:59 +00:00
class TeamTable(tables.Table):
2020-05-11 12:08:19 +00:00
"""
Table of some teams. Can be filtered with a queryset (for example, teams of a tournament)
"""
2020-04-29 15:58:11 +00:00
name = tables.LinkColumn(
"tournament:team_detail",
args=[A("pk")],
)
2020-04-29 14:59:59 +00:00
class Meta:
model = Team
fields = ("name", "trigram", "validation_status", )
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
2020-05-05 14:04:53 +00:00
order_by = ('-validation_status', 'trigram',)
2020-04-30 18:11:03 +00:00
class SolutionTable(tables.Table):
2020-05-11 12:08:19 +00:00
"""
Display a table of some solutions.
"""
2020-05-04 21:37:21 +00:00
team = tables.LinkColumn(
"tournament:team_detail",
args=[A("team.pk")],
)
tournament = tables.LinkColumn(
"tournament:detail",
2020-05-04 22:11:38 +00:00
args=[A("tournament.pk")],
accessor=A("tournament"),
2020-05-06 12:39:03 +00:00
order_by=("team__tournament__date_start", "team__tournament__name",),
verbose_name=_("Tournament"),
2020-05-04 21:37:21 +00:00
)
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):
2020-05-11 12:08:19 +00:00
"""
Display a table of some syntheses.
"""
2020-05-04 22:11:38 +00:00
team = tables.LinkColumn(
"tournament:team_detail",
args=[A("team.pk")],
)
tournament = tables.LinkColumn(
"tournament:detail",
args=[A("tournament.pk")],
accessor=A("tournament"),
2020-05-06 12:39:03 +00:00
order_by=("team__tournament__date_start", "team__tournament__name",),
2020-05-05 22:15:46 +00:00
verbose_name=_("tournament"),
2020-05-04 22:11:38 +00:00
)
2020-04-30 18:11:03 +00:00
file = tables.LinkColumn(
"document",
args=[A("file")],
attrs={
"a": {
"data-turbolinks": "false",
}
}
)
def render_file(self):
return _("Download")
class Meta:
2020-05-04 22:11:38 +00:00
model = Synthesis
fields = ("team", "tournament", "round", "source", "uploaded_at", "file", )
2020-04-30 18:11:03 +00:00
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
2020-05-05 02:45:38 +00:00
class PoolTable(tables.Table):
2020-05-11 12:08:19 +00:00
"""
Display a table of some pools.
"""
2020-05-06 12:39:03 +00:00
problems = tables.Column(
verbose_name=_("Problems"),
orderable=False,
)
2020-05-05 22:15:46 +00:00
2020-05-06 12:39:03 +00:00
tournament = tables.LinkColumn(
"tournament:detail",
args=[A("tournament.pk")],
verbose_name=_("Tournament"),
order_by=("teams__tournament__date_start", "teams__tournament__name",),
)
2020-05-05 22:15:46 +00:00
2020-05-06 12:39:03 +00:00
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()))
2020-05-05 02:45:38 +00:00
def render_problems(self, value):
return ", ".join([str(pb) for pb in value])
class Meta:
model = Pool
2020-05-06 12:39:03 +00:00
fields = ("teams", "tournament", "problems", "round", )
2020-05-05 02:45:38 +00:00
attrs = {
'class': 'table table-condensed table-striped table-hover'
}