1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-22 15:58:24 +02:00

Add observer team

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2024-07-05 11:47:19 +02:00
parent 2a298a3ee4
commit 05a6570bed
10 changed files with 486 additions and 191 deletions

View File

@ -5,6 +5,7 @@ import os
from asgiref.sync import sync_to_async
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.db.models import QuerySet
@ -199,7 +200,7 @@ class Round(models.Model):
(3, _('Round 3'))],
verbose_name=_('number'),
help_text=_("The number of the round, 1 or 2 (or 3 for ETEAM)"),
validators=[MinValueValidator(1), MaxValueValidator(settings.NB_ROUNDS)],
validators=[MinValueValidator(1), MaxValueValidator(3)],
)
current_pool = models.ForeignKey(
@ -233,6 +234,13 @@ class Round(models.Model):
def __str__(self):
return self.get_number_display()
def clean(self):
if self.number is not None and self.number > settings.NB_ROUNDS:
raise ValidationError({'number': _("The number of the round must be between 1 and {nb}.")
.format(nb=settings.NB_ROUNDS)})
return super().clean()
class Meta:
verbose_name = _('round')
verbose_name_plural = _('rounds')
@ -392,11 +400,11 @@ class Pool(models.Model):
]
elif self.size == 5:
table = [
[0, 2, 3],
[1, 3, 4],
[2, 4, 0],
[3, 0, 1],
[4, 1, 2],
[0, 2, 3, 4],
[1, 3, 4, 0],
[2, 4, 0, 1],
[3, 0, 1, 2],
[4, 1, 2, 3],
]
for i, line in enumerate(table):
@ -408,14 +416,20 @@ class Pool(models.Model):
passage_pool = pool2
passage_position = 1 + i // 2
defender = tds[line[0]].participation
opponent = tds[line[1]].participation
reviewer = tds[line[2]].participation
observer = tds[line[3]].participation if self.size >= 4 and settings.TFJM_APP == "ETEAM" else None
# Create the passage
await Passage.objects.acreate(
pool=passage_pool,
position=passage_position,
solution_number=tds[line[0]].accepted,
defender=tds[line[0]].participation,
opponent=tds[line[1]].participation,
reviewer=tds[line[2]].participation,
defender=defender,
opponent=opponent,
reviewer=reviewer,
observer=observer,
defender_penalties=tds[line[0]].penalty_int,
)