plateforme-tfjm2/apps/participation/tables.py

68 lines
2.0 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
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
2020-12-30 11:13:05 +00:00
from .models import 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 = {
'class': 'table table condensed table-striped',
}
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(
'participation:participation_detail',
args=[tables.A("id")],
verbose_name=lambda: _("name").capitalize(),
accessor="team__name",
)
trigram = tables.Column(
verbose_name=lambda: _("trigram").capitalize(),
accessor="team__trigram",
)
class Meta:
attrs = {
'class': 'table table condensed table-striped',
}
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 = {
'class': 'table table condensed table-striped',
}
model = Tournament
fields = ('name', 'date',)
template_name = 'django_tables2/bootstrap4.html'