mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-29 10:30:56 +02:00
Move apps in main directory
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
137
participation/tables.py
Normal file
137
participation/tables.py
Normal file
@ -0,0 +1,137 @@
|
||||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.utils import formats
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
import django_tables2 as tables
|
||||
|
||||
from .models import Note, Passage, Pool, Team, Tournament
|
||||
|
||||
|
||||
# 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
|
||||
fields = ('name', 'trigram',)
|
||||
|
||||
|
||||
# noinspection PyTypeChecker
|
||||
class ParticipationTable(tables.Table):
|
||||
name = tables.LinkColumn(
|
||||
'participation:team_detail',
|
||||
args=[tables.A("team__id")],
|
||||
verbose_name=_("name").capitalize,
|
||||
accessor="team__name",
|
||||
)
|
||||
|
||||
trigram = tables.Column(
|
||||
verbose_name=_("trigram").capitalize,
|
||||
accessor="team__trigram",
|
||||
)
|
||||
|
||||
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")
|
||||
|
||||
class Meta:
|
||||
attrs = {
|
||||
'class': 'table table-condensed table-striped',
|
||||
}
|
||||
model = Team
|
||||
fields = ('name', 'trigram', 'valid',)
|
||||
|
||||
|
||||
class TournamentTable(tables.Table):
|
||||
name = tables.LinkColumn()
|
||||
|
||||
date = tables.Column(_("date").capitalize, accessor="id")
|
||||
|
||||
def render_date(self, record):
|
||||
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))
|
||||
|
||||
class Meta:
|
||||
attrs = {
|
||||
'class': 'table table-condensed table-striped',
|
||||
}
|
||||
model = Tournament
|
||||
fields = ('name', 'date',)
|
||||
order_by = ('name', )
|
||||
|
||||
|
||||
class PoolTable(tables.Table):
|
||||
teams = tables.LinkColumn(
|
||||
'participation:pool_detail',
|
||||
args=[tables.A('id')],
|
||||
verbose_name=_("teams").capitalize,
|
||||
empty_values=(),
|
||||
)
|
||||
|
||||
def render_teams(self, record):
|
||||
return ", ".join(participation.team.trigram for participation in record.participations.all()) \
|
||||
or _("No defined team")
|
||||
|
||||
class Meta:
|
||||
attrs = {
|
||||
'class': 'table table-condensed table-striped',
|
||||
}
|
||||
model = Pool
|
||||
fields = ('teams', 'round', 'tournament',)
|
||||
|
||||
|
||||
class PassageTable(tables.Table):
|
||||
defender = tables.LinkColumn(
|
||||
"participation:passage_detail",
|
||||
args=[tables.A("id")],
|
||||
verbose_name=_("defender").capitalize,
|
||||
)
|
||||
|
||||
def render_defender(self, value):
|
||||
return value.team.trigram
|
||||
|
||||
def render_opponent(self, value):
|
||||
return value.team.trigram
|
||||
|
||||
def render_reporter(self, value):
|
||||
return value.team.trigram
|
||||
|
||||
class Meta:
|
||||
attrs = {
|
||||
'class': 'table table-condensed table-striped text-center',
|
||||
}
|
||||
model = Passage
|
||||
fields = ('defender', 'opponent', 'reporter', 'solution_number', )
|
||||
|
||||
|
||||
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',)
|
Reference in New Issue
Block a user