mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-24 03:08:52 +02:00
@ -1,5 +1,6 @@
|
||||
# Copyright (C) 2023 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from asgiref.sync import sync_to_async
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.utils.text import format_lazy
|
||||
@ -24,6 +25,52 @@ class Draw(models.Model):
|
||||
verbose_name=_('current round'),
|
||||
)
|
||||
|
||||
def get_state(self):
|
||||
if self.current_round.current_pool is None:
|
||||
return 'DICE_SELECT_POULES'
|
||||
elif self.current_round.current_pool.current_team is None:
|
||||
return 'DICE_ORDER_POULE'
|
||||
elif self.current_round.current_pool.current_team.purposed is None:
|
||||
return 'WAITING_DRAW_PROBLEM'
|
||||
elif self.current_round.current_pool.current_team.accepted is None:
|
||||
return 'WAITING_CHOOSE_PROBLEM'
|
||||
else:
|
||||
return 'DRAW_ENDED'
|
||||
|
||||
@property
|
||||
def information(self):
|
||||
s = ""
|
||||
match self.get_state():
|
||||
case 'DICE_SELECT_POULES':
|
||||
if self.current_round.number == 1:
|
||||
s += """Nous allons commencer le tirage des problèmes.<br>
|
||||
Vous pouvez à tout moment poser toute question si quelque chose
|
||||
n'est pas clair ou ne va pas.<br><br>
|
||||
Nous allons d'abord tirer les poules et l'ordre de passage
|
||||
pour le premier tour avec toutes les équipes puis pour chaque poule,
|
||||
nous tirerons l'ordre de tirage pour le tour et les problèmes.<br><br>"""
|
||||
s += """
|
||||
Les capitaines, vous pouvez désormais toustes lancer un dé 100,
|
||||
en cliquant sur le gros bouton. Les poules et l'ordre de passage
|
||||
lors du premier tour sera l'ordre croissant des dés, c'est-à-dire
|
||||
que le plus petit lancer sera le premier à passer dans la poule A."""
|
||||
case 'DICE_ORDER_POULE':
|
||||
s += f"""Nous passons au tirage des problèmes pour la poule
|
||||
<strong>{self.current_round.current_pool}</strong>, entre les équipes
|
||||
<strong>{', '.join(td.participation.team.trigram
|
||||
for td in self.current_round.current_pool.teamdraw_set.all())}</strong>.
|
||||
Les capitaines peuvent lancer un dé 100 en cliquant sur le gros bouton
|
||||
pour déterminer l'ordre de tirage. L'équipe réalisant le plus gros score pourra
|
||||
tirer en premier."""
|
||||
|
||||
s += """<br><br>Pour plus de détails sur le déroulement du tirage au sort,
|
||||
le règlement est accessible sur
|
||||
<a class="alert-link" href="https://tfjm.org/reglement">https://tfjm.org/reglement</a>."""
|
||||
return s
|
||||
|
||||
async def ainformation(self):
|
||||
return await sync_to_async(lambda: self.information)()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('draw')
|
||||
verbose_name_plural = _('draws')
|
||||
@ -89,8 +136,12 @@ class Pool(models.Model):
|
||||
verbose_name=_('current team'),
|
||||
)
|
||||
|
||||
@property
|
||||
def trigrams(self):
|
||||
return set(td.participation.team.trigram for td in self.teamdraw_set.all())
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.letter}{self.round}"
|
||||
return f"{self.get_letter_display()}{self.round.number}"
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('pool')
|
||||
@ -104,6 +155,12 @@ class TeamDraw(models.Model):
|
||||
verbose_name=_('participation'),
|
||||
)
|
||||
|
||||
round = models.ForeignKey(
|
||||
Round,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_('round'),
|
||||
)
|
||||
|
||||
pool = models.ForeignKey(
|
||||
Pool,
|
||||
on_delete=models.CASCADE,
|
||||
@ -112,11 +169,18 @@ class TeamDraw(models.Model):
|
||||
verbose_name=_('pool'),
|
||||
)
|
||||
|
||||
index = models.PositiveSmallIntegerField(
|
||||
choices=zip(range(1, 6), range(1, 6)),
|
||||
passage_index = models.PositiveSmallIntegerField(
|
||||
choices=zip(range(1, 5), range(1, 5)),
|
||||
null=True,
|
||||
default=None,
|
||||
verbose_name=_('index'),
|
||||
verbose_name=_('passage index'),
|
||||
)
|
||||
|
||||
choose_index = models.PositiveSmallIntegerField(
|
||||
choices=zip(range(1, 5), range(1, 5)),
|
||||
null=True,
|
||||
default=None,
|
||||
verbose_name=_('choose index'),
|
||||
)
|
||||
|
||||
accepted = models.PositiveSmallIntegerField(
|
||||
@ -149,6 +213,9 @@ class TeamDraw(models.Model):
|
||||
verbose_name=_('rejected problems'),
|
||||
)
|
||||
|
||||
def current(self):
|
||||
return TeamDraw.objects.get(participation=self.participation, round=self.round.draw.current_round)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('team draw')
|
||||
verbose_name_plural = _('team draws')
|
||||
|
Reference in New Issue
Block a user