mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 01:18:22 +02:00
@ -1,2 +1,62 @@
|
||||
# Copyright (C) 2023 by Animath
|
||||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import Draw, Round, Pool, TeamDraw
|
||||
|
||||
|
||||
@admin.register(Draw)
|
||||
class DrawAdmin(admin.ModelAdmin):
|
||||
list_display = ('tournament', 'teams', 'current_round', 'get_state',)
|
||||
list_filter = ('tournament', 'current_round',)
|
||||
search_fields = ('tournament__name', 'tournament__participation__team__trigram',)
|
||||
|
||||
@admin.display(description=_("teams"))
|
||||
def teams(self, record: Draw):
|
||||
return ', '.join(p.team.trigram for p in record.tournament.participations.filter(valid=True).all())
|
||||
|
||||
|
||||
@admin.register(Round)
|
||||
class RoundAdmin(admin.ModelAdmin):
|
||||
list_display = ('draw', 'number', 'teams',)
|
||||
list_filter = ('draw__tournament', 'number',)
|
||||
search_fields = ('draw__tournament__name', 'pool__teamdraw__participation__team__trigram')
|
||||
ordering = ('draw__tournament__name', 'number')
|
||||
|
||||
@admin.display(description=_("teams"))
|
||||
def teams(self, record: Round):
|
||||
return ', '.join(td.participation.team.trigram for td in record.team_draws)
|
||||
|
||||
|
||||
@admin.register(Pool)
|
||||
class PoolAdmin(admin.ModelAdmin):
|
||||
list_display = ('tournament', 'round', 'letter', 'teams')
|
||||
list_filter = ('round__draw__tournament', 'round__number', 'letter')
|
||||
ordering = ('round__draw__tournament__name', 'round', 'letter')
|
||||
search_fields = ('round__draw__tournament__name', 'teamdraw__participation__team__trigram',)
|
||||
|
||||
@admin.display(ordering='round__draw__tournament__name', description=_("tournament"))
|
||||
def tournament(self, record):
|
||||
return record.round.draw.tournament
|
||||
|
||||
@admin.display(description=_("teams"))
|
||||
def teams(self, record: Round):
|
||||
return ', '.join(td.participation.team.trigram for td in record.team_draws)
|
||||
|
||||
|
||||
@admin.register(TeamDraw)
|
||||
class TeamDrawAdmin(admin.ModelAdmin):
|
||||
list_display = ('participation', 'tournament', 'view_round', 'pool', 'accepted', 'rejected',
|
||||
'passage_index', 'choose_index', 'passage_dice', 'choice_dice',)
|
||||
list_filter = ('round__draw__tournament', 'round__number', 'pool__letter',)
|
||||
search_fields = ('round__draw__tournament__name', 'participation__team__trigram',)
|
||||
|
||||
@admin.display(ordering='round__draw__tournament__name', description=_("tournament"))
|
||||
def tournament(self, record):
|
||||
return record.round.draw.tournament
|
||||
|
||||
@admin.display(ordering='round__number', description=_('round'))
|
||||
def view_round(self, record):
|
||||
return record.round.get_number_display()
|
@ -0,0 +1,65 @@
|
||||
# Generated by Django 4.1.7 on 2023-04-03 16:10
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("draw", "0008_alter_pool_letter"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="pool",
|
||||
options={
|
||||
"ordering": (
|
||||
"round__draw__tournament__name",
|
||||
"round__number",
|
||||
"letter",
|
||||
),
|
||||
"verbose_name": "pool",
|
||||
"verbose_name_plural": "pools",
|
||||
},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="round",
|
||||
options={
|
||||
"ordering": ("draw__tournament__name", "number"),
|
||||
"verbose_name": "round",
|
||||
"verbose_name_plural": "rounds",
|
||||
},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="teamdraw",
|
||||
options={
|
||||
"ordering": (
|
||||
"round__draw__tournament__name",
|
||||
"round__number",
|
||||
"pool__letter",
|
||||
"passage_index",
|
||||
),
|
||||
"verbose_name": "team draw",
|
||||
"verbose_name_plural": "team draws",
|
||||
},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="teamdraw",
|
||||
name="choose_index",
|
||||
field=models.PositiveSmallIntegerField(
|
||||
choices=[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)],
|
||||
default=None,
|
||||
null=True,
|
||||
verbose_name="choose index",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="teamdraw",
|
||||
name="passage_index",
|
||||
field=models.PositiveSmallIntegerField(
|
||||
choices=[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)],
|
||||
default=None,
|
||||
null=True,
|
||||
verbose_name="passage index",
|
||||
),
|
||||
),
|
||||
]
|
@ -4,7 +4,8 @@
|
||||
from asgiref.sync import sync_to_async
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.utils.text import format_lazy
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.text import format_lazy, slugify
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from participation.models import Passage, Participation, Pool as PPool, Tournament
|
||||
@ -32,6 +33,9 @@ class Draw(models.Model):
|
||||
verbose_name=_("last message"),
|
||||
)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse_lazy('draw:index') + f'#{slugify(self.tournament.name)}'
|
||||
|
||||
@property
|
||||
def exportable(self):
|
||||
return any(pool.exportable for r in self.round_set.all() for pool in r.pool_set.all())
|
||||
@ -110,6 +114,9 @@ class Draw(models.Model):
|
||||
async def ainformation(self):
|
||||
return await sync_to_async(lambda: self.information)()
|
||||
|
||||
def __str__(self):
|
||||
return str(format_lazy(_("Draw of tournament {tournament}"), tournament=self.tournament.name))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('draw')
|
||||
verbose_name_plural = _('draws')
|
||||
@ -153,6 +160,7 @@ class Round(models.Model):
|
||||
class Meta:
|
||||
verbose_name = _('round')
|
||||
verbose_name_plural = _('rounds')
|
||||
ordering = ('draw__tournament__name', 'number',)
|
||||
|
||||
|
||||
class Pool(models.Model):
|
||||
@ -265,11 +273,12 @@ class Pool(models.Model):
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.get_letter_display()}{self.round.number}"
|
||||
return str(format_lazy(_("Pool {letter}{number}"), letter=self.get_letter_display(), number=self.round.number))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('pool')
|
||||
verbose_name_plural = _('pools')
|
||||
ordering = ('round__draw__tournament__name', 'round__number', 'letter',)
|
||||
|
||||
|
||||
class TeamDraw(models.Model):
|
||||
@ -294,14 +303,14 @@ class TeamDraw(models.Model):
|
||||
)
|
||||
|
||||
passage_index = models.PositiveSmallIntegerField(
|
||||
choices=zip(range(1, 5), range(1, 5)),
|
||||
choices=zip(range(1, 6), range(1, 6)),
|
||||
null=True,
|
||||
default=None,
|
||||
verbose_name=_('passage index'),
|
||||
)
|
||||
|
||||
choose_index = models.PositiveSmallIntegerField(
|
||||
choices=zip(range(1, 5), range(1, 5)),
|
||||
choices=zip(range(1, 6), range(1, 6)),
|
||||
null=True,
|
||||
default=None,
|
||||
verbose_name=_('choose index'),
|
||||
@ -356,6 +365,13 @@ class TeamDraw(models.Model):
|
||||
def penalty(self):
|
||||
return 0.5 * self.penalty_int
|
||||
|
||||
def __str__(self):
|
||||
return str(format_lazy(_("Draw of the team {trigram} for the pool {letter}{number}"),
|
||||
trigram=self.participation.team.trigram,
|
||||
letter=self.pool.get_letter_display() if self.pool else "",
|
||||
number=self.round.number))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('team draw')
|
||||
verbose_name_plural = _('team draws')
|
||||
ordering = ('round__draw__tournament__name', 'round__number', 'pool__letter', 'passage_index',)
|
||||
|
@ -67,7 +67,7 @@
|
||||
<li id="recap-{{ tournament.id }}-round-{{ round.number }}-pool-{{ pool.get_letter_display }}"
|
||||
class="list-group-item px-3 py-3 {% if tournament.draw.current_round.current_pool == pool %} list-group-item-success{% endif %}"
|
||||
data-tournament="{{ tournament.id }}">
|
||||
<strong>{% trans "pool"|capfirst %} {{ pool }}</strong>
|
||||
<strong>{{ pool }}</strong>
|
||||
<ul id="recap-{{ tournament.id }}-round-{{ round.number }}-pool-{{ pool.get_letter_display }}-team-list"
|
||||
class="list-group list-group-flush">
|
||||
{% for td in pool.team_draws.all %}
|
||||
@ -182,7 +182,7 @@
|
||||
<div class="card w-100 my-3 order-{{ pool.letter }}">
|
||||
<div class="card-header">
|
||||
<h3>
|
||||
{% trans "pool"|capfirst %} {{ pool }}
|
||||
{{ pool }}
|
||||
</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
Reference in New Issue
Block a user