plateforme-tfjm2/apps/participation/tables.py

118 lines
3.3 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
2021-01-13 15:22:26 +00:00
2020-12-31 11:23:09 +00:00
from django.utils import formats
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 17:43:53 +00:00
from .models import Note, 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
template_name = 'django_tables2/bootstrap4.html'
# 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',)
2020-12-27 10:49:54 +00:00
template_name = 'django_tables2/bootstrap4.html'
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',)
template_name = 'django_tables2/bootstrap4.html'
2021-01-13 15:22:26 +00:00
class PoolTable(tables.Table):
teams = tables.LinkColumn(
'participation:pool_detail',
args=[tables.A('id')],
2021-01-13 16:00:50 +00:00
verbose_name=_("teams").capitalize,
empty_values=(),
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 = ('teams', 'round', 'tournament',)
template_name = 'django_tables2/bootstrap4.html'
2021-01-14 17:43:53 +00:00
class NoteTable(tables.Table):
jury = tables.Column(
attrs={
"td": {
"class": "text-nowrap",
}
}
)
class Meta:
attrs = {
'class': 'table table-condensed table-striped text-center',
}
model = Note
fields = ('jury', 'defender_writing', 'defender_oral', 'opponent_writing', 'opponent_oral',
'reporter_writing', 'reporter_oral',)
template_name = 'django_tables2/bootstrap4.html'