From 4357d51b9ad7c6439c1c5b94cde839f9b771b2b3 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Tue, 4 Apr 2023 11:56:13 +0200 Subject: [PATCH] Display problem names Signed-off-by: Emmy D'Anello --- draw/consumers.py | 10 ++++++---- draw/models.py | 10 +++++----- participation/models.py | 4 ++-- tfjm/settings.py | 11 ++++++++++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/draw/consumers.py b/draw/consumers.py index 39eeef1..48ce726 100644 --- a/draw/consumers.py +++ b/draw/consumers.py @@ -382,7 +382,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): return await self.alert("This is not your turn.", 'danger') while True: - problem = randint(1, settings.PROBLEM_COUNT) + problem = randint(1, len(settings.PROBLEMS)) if await TeamDraw.objects.filter(participation_id=td.participation_id, round__draw__tournament=self.tournament, round__number=1, @@ -431,7 +431,8 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): await td.asave() trigram = await sync_to_async(lambda: td.participation.team.trigram)() - msg = f"L'équipe {trigram} a accepté le problème {td.accepted}. " + msg = f"L'équipe {trigram} a accepté le problème {td.accepted} : " \ + f"{settings.PROBLEMS[td.accepted - 1]}. " if pool.size == 5 and await pool.teamdraw_set.filter(accepted=td.accepted).acount() < 2: msg += "Une équipe peut encore l'accepter." else: @@ -574,10 +575,11 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): td.purposed = None await td.asave() - remaining = settings.PROBLEM_COUNT - 5 - len(td.rejected) + remaining = len(settings.PROBLEMS) - 5 - len(td.rejected) trigram = await sync_to_async(lambda: td.participation.team.trigram)() - msg = f"L'équipe {trigram} a refusé le problème {problem}. " + msg = f"L'équipe {trigram} a refusé le problème {problem} : " \ + f"{settings.PROBLEMS[problem - 1]}. " if remaining >= 0: msg += f"Il lui reste {remaining} refus sans pénalité." else: diff --git a/draw/models.py b/draw/models.py index 36e373c..56ffc0c 100644 --- a/draw/models.py +++ b/draw/models.py @@ -96,10 +96,10 @@ class Draw(models.Model): tirer un nouveau problème immédiatement, ou bien revenir sur son choix.""" else: s += "Elle peut décider d'accepter ou de refuser ce problème. " - if len(td.rejected) >= settings.PROBLEM_COUNT - 5: + if len(td.rejected) >= len(settings.PROBLEMS) - 5: s += "Refuser ce problème ajoutera une nouvelle pénalité de 0.5 sur le coefficient de l'oral de læ défenseur⋅se." else: - s += f"Il reste {settings.PROBLEM_COUNT - 5 - len(td.rejected)} refus sans pénalité." + s += f"Il reste {len(settings.PROBLEMS) - 5 - len(td.rejected)} refus sans pénalité." case 'WAITING_FINAL': s += "Le tirage au sort pour le tour 2 aura lieu à la fin du premier tour. Bon courage !" case 'DRAW_ENDED': @@ -318,7 +318,7 @@ class TeamDraw(models.Model): accepted = models.PositiveSmallIntegerField( choices=[ - (i, format_lazy(_("Problem #{problem}"), problem=i)) for i in range(1, settings.PROBLEM_COUNT + 1) + (i, format_lazy(_("Problem #{problem}"), problem=i)) for i in range(1, len(settings.PROBLEMS) + 1) ], null=True, default=None, @@ -341,7 +341,7 @@ class TeamDraw(models.Model): purposed = models.PositiveSmallIntegerField( choices=[ - (i, format_lazy(_("Problem #{problem}"), problem=i)) for i in range(1, settings.PROBLEM_COUNT + 1) + (i, format_lazy(_("Problem #{problem}"), problem=i)) for i in range(1, len(settings.PROBLEMS) + 1) ], null=True, default=None, @@ -359,7 +359,7 @@ class TeamDraw(models.Model): @property def penalty_int(self): - return max(0, len(self.rejected) - (settings.PROBLEM_COUNT - 5)) + return max(0, len(self.rejected) - (len(settings.PROBLEMS) - 5)) @property def penalty(self): diff --git a/participation/models.py b/participation/models.py index b737237..c9de872 100644 --- a/participation/models.py +++ b/participation/models.py @@ -431,7 +431,7 @@ class Passage(models.Model): solution_number = models.PositiveSmallIntegerField( verbose_name=_("defended solution"), choices=[ - (i, format_lazy(_("Problem #{problem}"), problem=i)) for i in range(1, settings.PROBLEM_COUNT + 1) + (i, format_lazy(_("Problem #{problem}"), problem=i)) for i in range(1, len(settings.PROBLEMS) + 1) ], ) @@ -585,7 +585,7 @@ class Solution(models.Model): problem = models.PositiveSmallIntegerField( verbose_name=_("problem"), choices=[ - (i, format_lazy(_("Problem #{problem}"), problem=i)) for i in range(1, settings.PROBLEM_COUNT + 1) + (i, format_lazy(_("Problem #{problem}"), problem=i)) for i in range(1, len(settings.PROBLEMS) + 1) ], ) diff --git a/tfjm/settings.py b/tfjm/settings.py index 4b7489c..9b28844 100644 --- a/tfjm/settings.py +++ b/tfjm/settings.py @@ -234,7 +234,16 @@ PHONENUMBER_DEFAULT_REGION = 'FR' GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY") # Custom parameters -PROBLEM_COUNT = 8 +PROBLEMS = [ + "Philatélie", + "La montagne aux ruisseaux", + "Appoint monétaire", + "Musique déformée", + "Angles entiers", + "Tribus hiérarchiques", + "Miroirs et lasers", + "Graine de deck", +] FORBIDDEN_TRIGRAMS = [ "BIT", "CNO",