2020-12-27 10:49:54 +00:00
|
|
|
# Copyright (C) 2020 by Animath
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2024-03-26 20:18:03 +00:00
|
|
|
|
2020-12-31 11:23:09 +00:00
|
|
|
from django.utils import formats
|
2024-03-24 10:28:41 +00:00
|
|
|
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',)
|
2023-04-11 20:41:52 +00:00
|
|
|
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):
|
2023-03-31 15:23:40 +00:00
|
|
|
letter = tables.LinkColumn(
|
2021-01-13 15:22:26 +00:00
|
|
|
'participation:pool_detail',
|
|
|
|
args=[tables.A('id')],
|
2023-03-31 15:23:40 +00:00
|
|
|
verbose_name=_("pool").capitalize,
|
|
|
|
)
|
|
|
|
|
|
|
|
teams = tables.Column(
|
2021-01-13 16:00:50 +00:00
|
|
|
verbose_name=_("teams").capitalize,
|
|
|
|
empty_values=(),
|
2023-04-16 07:25:00 +00:00
|
|
|
orderable=False,
|
2021-01-13 15:22:26 +00:00
|
|
|
)
|
|
|
|
|
2023-03-31 15:23:40 +00:00
|
|
|
def render_letter(self, record):
|
2024-04-18 12:53:58 +00:00
|
|
|
return format_lazy(_("Pool {code}"), code=record.short_name)
|
2023-03-31 15:23:40 +00:00
|
|
|
|
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
|
2023-03-31 15:23:40 +00:00
|
|
|
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):
|
2024-07-05 09:47:19 +00:00
|
|
|
# FIXME Ne pas afficher l'équipe observatrice si non nécessaire
|
|
|
|
|
2021-01-14 18:33:56 +00:00
|
|
|
defender = tables.LinkColumn(
|
|
|
|
"participation:passage_detail",
|
|
|
|
args=[tables.A("id")],
|
|
|
|
verbose_name=_("defender").capitalize,
|
|
|
|
)
|
|
|
|
|
|
|
|
def render_defender(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
|
|
|
|
2024-07-05 09:00:11 +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
|
|
|
|
2024-07-05 09:47:19 +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
|
2024-07-05 09:47:19 +00:00
|
|
|
fields = ('defender', '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",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-03-24 10:28:41 +00:00
|
|
|
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', 'defender_writing', 'defender_oral', 'opponent_writing', 'opponent_oral',
|
2024-07-05 09:47:19 +00:00
|
|
|
'reviewer_writing', 'reviewer_oral', 'observer_writing', 'observer_oral', 'update',)
|