plateforme-tfjm2/participation/tables.py

164 lines
4.5 KiB
Python
Raw Normal View History

2020-12-27 10:49:54 +00:00
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
2020-12-31 11:23:09 +00:00
from django.utils import formats
from django.utils.safestring import mark_safe
2020-12-30 11:13:05 +00:00
from django.utils.text import format_lazy
2020-12-27 10:49:54 +00:00
from django.utils.translation import gettext_lazy as _
import django_tables2 as tables
2021-01-14 18:33:56 +00:00
from .models import Note, Passage, Pool, Team, Tournament
2020-12-27 10:49:54 +00:00
# noinspection PyTypeChecker
class TeamTable(tables.Table):
name = tables.LinkColumn(
'participation:team_detail',
args=[tables.A("id")],
verbose_name=lambda: _("name").capitalize(),
)
class Meta:
attrs = {
2021-01-14 17:43:53 +00:00
'class': 'table table-condensed table-striped',
2020-12-27 10:49:54 +00:00
}
model = Team
2021-01-01 11:11:09 +00:00
fields = ('name', 'trigram',)
2020-12-27 10:49:54 +00:00
# noinspection PyTypeChecker
class ParticipationTable(tables.Table):
name = tables.LinkColumn(
2021-01-01 23:06:58 +00:00
'participation:team_detail',
args=[tables.A("team__id")],
verbose_name=_("name").capitalize,
2020-12-27 10:49:54 +00:00
accessor="team__name",
)
trigram = tables.Column(
2021-01-01 23:06:58 +00:00
verbose_name=_("trigram").capitalize,
2020-12-27 10:49:54 +00:00
accessor="team__trigram",
)
2021-01-01 23:06:58 +00:00
valid = tables.Column(
verbose_name=_("valid").capitalize,
accessor="valid",
empty_values=(),
)
def render_valid(self, value):
return _("Validated") if value else _("Validation pending") if value is False else _("Not validated")
2020-12-27 10:49:54 +00:00
class Meta:
attrs = {
2021-01-14 17:43:53 +00:00
'class': 'table table-condensed table-striped',
2020-12-27 10:49:54 +00:00
}
model = Team
2021-01-01 11:11:09 +00:00
fields = ('name', 'trigram', 'valid',)
order = ('-valid',)
2020-12-30 11:13:05 +00:00
class TournamentTable(tables.Table):
2020-12-31 11:23:09 +00:00
name = tables.LinkColumn()
date = tables.Column(_("date").capitalize, accessor="id")
2020-12-30 11:13:05 +00:00
def render_date(self, record):
2020-12-31 11:23:09 +00:00
return format_lazy(_("From {start} to {end}"),
start=formats.date_format(record.date_start, format="SHORT_DATE_FORMAT", use_l10n=True),
end=formats.date_format(record.date_end, format="SHORT_DATE_FORMAT", use_l10n=True))
2020-12-30 11:13:05 +00:00
class Meta:
attrs = {
2021-01-14 17:43:53 +00:00
'class': 'table table-condensed table-striped',
2020-12-30 11:13:05 +00:00
}
model = Tournament
fields = ('name', 'date',)
2021-01-22 21:33:48 +00:00
order_by = ('name', )
2021-01-13 15:22:26 +00:00
class PoolTable(tables.Table):
letter = tables.LinkColumn(
2021-01-13 15:22:26 +00:00
'participation:pool_detail',
args=[tables.A('id')],
verbose_name=_("pool").capitalize,
)
teams = tables.Column(
2021-01-13 16:00:50 +00:00
verbose_name=_("teams").capitalize,
empty_values=(),
orderable=False,
2021-01-13 15:22:26 +00:00
)
def render_letter(self, record):
return format_lazy(_("Pool {code}"), code=record.short_name)
2021-01-13 15:22:26 +00:00
def render_teams(self, record):
2021-01-13 16:00:50 +00:00
return ", ".join(participation.team.trigram for participation in record.participations.all()) \
or _("No defined team")
2021-01-13 15:22:26 +00:00
class Meta:
attrs = {
2021-01-14 17:43:53 +00:00
'class': 'table table-condensed table-striped',
2021-01-13 15:22:26 +00:00
}
model = Pool
fields = ('letter', 'teams', 'round', 'tournament',)
2021-01-14 17:43:53 +00:00
2021-01-14 18:33:56 +00:00
class PassageTable(tables.Table):
# FIXME Ne pas afficher l'équipe observatrice si non nécessaire
reporter = tables.LinkColumn(
2021-01-14 18:33:56 +00:00
"participation:passage_detail",
args=[tables.A("id")],
verbose_name=_("reporter").capitalize,
2021-01-14 18:33:56 +00:00
)
def render_reporter(self, value):
2021-04-04 11:15:00 +00:00
return value.team.trigram
2021-01-14 18:33:56 +00:00
def render_opponent(self, value):
2021-04-04 11:15:00 +00:00
return value.team.trigram
2021-01-14 18:33:56 +00:00
def render_reviewer(self, value):
2021-04-04 11:15:00 +00:00
return value.team.trigram
2021-01-14 18:33:56 +00:00
def render_observer(self, value):
return value.team.trigram
2021-01-14 18:33:56 +00:00
class Meta:
attrs = {
'class': 'table table-condensed table-striped text-center',
}
model = Passage
fields = ('reporter', 'opponent', 'reviewer', 'observer', 'solution_number', )
2021-01-14 18:33:56 +00:00
2021-01-14 17:43:53 +00:00
class NoteTable(tables.Table):
jury = tables.Column(
attrs={
"td": {
"class": "text-nowrap",
}
}
)
update = tables.Column(
verbose_name=_("Update"),
accessor="id",
empty_values=(),
)
def render_update(self, record):
return mark_safe(f'<button class="btn btn-info" data-bs-toggle="modal" '
f'data-bs-target="#{record.modal_name}Modal">'
f'{_("Update")}</button>')
2021-01-14 17:43:53 +00:00
class Meta:
attrs = {
'class': 'table table-condensed table-striped text-center',
}
model = Note
fields = ('jury', 'reporter_writing', 'reporter_oral', 'opponent_writing', 'opponent_oral',
'reviewer_writing', 'reviewer_oral', 'observer_writing', 'observer_oral', 'update',)