From cf8892ee1abfe1b5c963cb918b62a9e0625cc578 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Tue, 28 Mar 2023 21:56:18 +0200 Subject: [PATCH] Use separate fields for the two dices Signed-off-by: Emmy D'Anello --- draw/consumers.py | 38 +-- ...last_dice_teamdraw_choice_dice_and_more.py | 238 ++++++++++++++++++ draw/models.py | 15 +- locale/fr/LC_MESSAGES/django.po | 73 +++--- 4 files changed, 311 insertions(+), 53 deletions(-) create mode 100644 draw/migrations/0007_remove_teamdraw_last_dice_teamdraw_choice_dice_and_more.py diff --git a/draw/consumers.py b/draw/consumers.py index 0a5b33f..5eed1d9 100644 --- a/draw/consumers.py +++ b/draw/consumers.py @@ -163,11 +163,11 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): if state == 'DICE_ORDER_POULE': participation = await Participation.objects\ .filter(teamdraw__pool=self.tournament.draw.current_round.current_pool, - teamdraw__last_dice__isnull=True).prefetch_related('team').afirst() + teamdraw__choice_dice__isnull=True).prefetch_related('team').afirst() else: participation = await Participation.objects\ .filter(teamdraw__round=self.tournament.draw.current_round, - teamdraw__last_dice__isnull=True).prefetch_related('team').afirst() + teamdraw__passage_dice__isnull=True).prefetch_related('team').afirst() trigram = participation.team.trigram else: participation = await Participation.objects.filter(team__participants=self.registration)\ @@ -179,10 +179,10 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): match state: case 'DICE_SELECT_POULES': - if team_draw.last_dice is not None: + if team_draw.passage_dice is not None: return await self.alert(_("You've already launched the dice."), 'danger') case 'DICE_ORDER_POULE': - if team_draw.last_dice is not None: + if team_draw.choice_dice is not None: return await self.alert(_("You've already launched the dice."), 'danger') if not await self.tournament.draw.current_round.current_pool.teamdraw_set\ .filter(participation=participation).aexists(): @@ -191,7 +191,10 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): return await self.alert(_("This is not the time for this."), 'danger') res = randint(1, 100) - team_draw.last_dice = res + if state == 'DICE_SELECT_POULES': + team_draw.passage_dice = res + else: + team_draw.choice_dice = res await sync_to_async(team_draw.save)() await self.channel_layer.group_send( @@ -199,21 +202,21 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): if state == 'DICE_SELECT_POULES' and \ not await TeamDraw.objects.filter(round_id=self.tournament.draw.current_round_id, - last_dice__isnull=True).aexists(): + passage_dice__isnull=True).aexists(): tds = [] async for td in TeamDraw.objects.filter(round_id=self.tournament.draw.current_round_id)\ .prefetch_related('participation__team'): tds.append(td) - dices = {td: td.last_dice for td in tds} + dices = {td: td.passage_dice for td in tds} values = list(dices.values()) error = False for v in set(values): if values.count(v) > 1: - dups = [td for td in tds if td.last_dice == v] + dups = [td for td in tds if td.passage_dice == v] for dup in dups: - dup.last_dice = None + dup.passage_dice = None await sync_to_async(dup.save)() await self.channel_layer.group_send( f"tournament-{self.tournament.id}", @@ -229,7 +232,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): if error: return - tds.sort(key=lambda td: td.last_dice) + tds.sort(key=lambda td: td.passage_dice) tds_copy = tds.copy() async for p in Pool.objects.filter(round_id=self.tournament.draw.current_round_id).order_by('letter').all(): @@ -247,7 +250,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): if await sync_to_async(lambda: set(td['id'] for td in p1.teamdraw_set.values('id')))() \ == await sync_to_async(lambda:set(td['id'] for td in p2.teamdraw_set.values('id')))(): await TeamDraw.objects.filter(round=self.tournament.draw.current_round)\ - .aupdate(last_dice=None, pool=None, passage_index=None) + .aupdate(passage_dice=None, pool=None, passage_index=None) for td in tds: await self.channel_layer.group_send( f"tournament-{self.tournament.id}", @@ -265,13 +268,12 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): msg = "Les résultats des dés sont les suivants : " msg += await sync_to_async(lambda: ", ".join( - f"{td.participation.team.trigram} ({td.last_dice})" + f"{td.participation.team.trigram} ({td.passage_dice})" for td in self.tournament.draw.current_round.team_draws))() msg += ". L'ordre de passage et les compositions des différentes poules sont affiché⋅es sur le côté." self.tournament.draw.last_message = msg await sync_to_async(self.tournament.draw.save)() - await TeamDraw.objects.filter(round=self.tournament.draw.current_round).aupdate(last_dice=None) for td in tds: await self.channel_layer.group_send( f"tournament-{self.tournament.id}", @@ -296,7 +298,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): {'type': 'draw.set_active', 'draw': self.tournament.draw}) elif state == 'DICE_ORDER_POULE' and \ not await TeamDraw.objects.filter(pool=self.tournament.draw.current_round.current_pool, - last_dice__isnull=True).aexists(): + choice_dice__isnull=True).aexists(): pool = self.tournament.draw.current_round.current_pool tds = [] @@ -304,15 +306,15 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): .prefetch_related('participation__team'): tds.append(td) - dices = {td: td.last_dice for td in tds} + dices = {td: td.choice_dice for td in tds} values = list(dices.values()) error = False for v in set(values): if values.count(v) > 1: - dups = [td for td in tds if td.last_dice == v] + dups = [td for td in tds if td.choice_dice == v] for dup in dups: - dup.last_dice = None + dup.choice_dice = None await sync_to_async(dup.save)() await self.channel_layer.group_send( f"tournament-{self.tournament.id}", @@ -328,7 +330,7 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): if error: return - tds.sort(key=lambda x: -x.last_dice) + tds.sort(key=lambda x: -x.choice_dice) for i, td in enumerate(tds): td.choose_index = i await sync_to_async(td.save)() diff --git a/draw/migrations/0007_remove_teamdraw_last_dice_teamdraw_choice_dice_and_more.py b/draw/migrations/0007_remove_teamdraw_last_dice_teamdraw_choice_dice_and_more.py new file mode 100644 index 0000000..832da99 --- /dev/null +++ b/draw/migrations/0007_remove_teamdraw_last_dice_teamdraw_choice_dice_and_more.py @@ -0,0 +1,238 @@ +# Generated by Django 4.1.7 on 2023-03-28 19:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("draw", "0006_pool_associated_pool"), + ] + + operations = [ + migrations.RemoveField( + model_name="teamdraw", + name="last_dice", + ), + migrations.AddField( + model_name="teamdraw", + name="choice_dice", + field=models.PositiveSmallIntegerField( + choices=[ + (1, 1), + (2, 2), + (3, 3), + (4, 4), + (5, 5), + (6, 6), + (7, 7), + (8, 8), + (9, 9), + (10, 10), + (11, 11), + (12, 12), + (13, 13), + (14, 14), + (15, 15), + (16, 16), + (17, 17), + (18, 18), + (19, 19), + (20, 20), + (21, 21), + (22, 22), + (23, 23), + (24, 24), + (25, 25), + (26, 26), + (27, 27), + (28, 28), + (29, 29), + (30, 30), + (31, 31), + (32, 32), + (33, 33), + (34, 34), + (35, 35), + (36, 36), + (37, 37), + (38, 38), + (39, 39), + (40, 40), + (41, 41), + (42, 42), + (43, 43), + (44, 44), + (45, 45), + (46, 46), + (47, 47), + (48, 48), + (49, 49), + (50, 50), + (51, 51), + (52, 52), + (53, 53), + (54, 54), + (55, 55), + (56, 56), + (57, 57), + (58, 58), + (59, 59), + (60, 60), + (61, 61), + (62, 62), + (63, 63), + (64, 64), + (65, 65), + (66, 66), + (67, 67), + (68, 68), + (69, 69), + (70, 70), + (71, 71), + (72, 72), + (73, 73), + (74, 74), + (75, 75), + (76, 76), + (77, 77), + (78, 78), + (79, 79), + (80, 80), + (81, 81), + (82, 82), + (83, 83), + (84, 84), + (85, 85), + (86, 86), + (87, 87), + (88, 88), + (89, 89), + (90, 90), + (91, 91), + (92, 92), + (93, 93), + (94, 94), + (95, 95), + (96, 96), + (97, 97), + (98, 98), + (99, 99), + (100, 100), + ], + default=None, + null=True, + verbose_name="choice dice", + ), + ), + migrations.AddField( + model_name="teamdraw", + name="passage_dice", + field=models.PositiveSmallIntegerField( + choices=[ + (1, 1), + (2, 2), + (3, 3), + (4, 4), + (5, 5), + (6, 6), + (7, 7), + (8, 8), + (9, 9), + (10, 10), + (11, 11), + (12, 12), + (13, 13), + (14, 14), + (15, 15), + (16, 16), + (17, 17), + (18, 18), + (19, 19), + (20, 20), + (21, 21), + (22, 22), + (23, 23), + (24, 24), + (25, 25), + (26, 26), + (27, 27), + (28, 28), + (29, 29), + (30, 30), + (31, 31), + (32, 32), + (33, 33), + (34, 34), + (35, 35), + (36, 36), + (37, 37), + (38, 38), + (39, 39), + (40, 40), + (41, 41), + (42, 42), + (43, 43), + (44, 44), + (45, 45), + (46, 46), + (47, 47), + (48, 48), + (49, 49), + (50, 50), + (51, 51), + (52, 52), + (53, 53), + (54, 54), + (55, 55), + (56, 56), + (57, 57), + (58, 58), + (59, 59), + (60, 60), + (61, 61), + (62, 62), + (63, 63), + (64, 64), + (65, 65), + (66, 66), + (67, 67), + (68, 68), + (69, 69), + (70, 70), + (71, 71), + (72, 72), + (73, 73), + (74, 74), + (75, 75), + (76, 76), + (77, 77), + (78, 78), + (79, 79), + (80, 80), + (81, 81), + (82, 82), + (83, 83), + (84, 84), + (85, 85), + (86, 86), + (87, 87), + (88, 88), + (89, 89), + (90, 90), + (91, 91), + (92, 92), + (93, 93), + (94, 94), + (95, 95), + (96, 96), + (97, 97), + (98, 98), + (99, 99), + (100, 100), + ], + default=None, + null=True, + verbose_name="passage dice", + ), + ), + ] diff --git a/draw/models.py b/draw/models.py index f91ac5d..bca165a 100644 --- a/draw/models.py +++ b/draw/models.py @@ -314,11 +314,18 @@ class TeamDraw(models.Model): verbose_name=_("accepted problem"), ) - last_dice = models.PositiveSmallIntegerField( + passage_dice = models.PositiveSmallIntegerField( choices=zip(range(1, 101), range(1, 101)), null=True, default=None, - verbose_name=_("last dice"), + verbose_name=_("passage dice"), + ) + + choice_dice = models.PositiveSmallIntegerField( + choices=zip(range(1, 101), range(1, 101)), + null=True, + default=None, + verbose_name=_("choice dice"), ) purposed = models.PositiveSmallIntegerField( @@ -335,6 +342,10 @@ class TeamDraw(models.Model): verbose_name=_('rejected problems'), ) + @property + def last_dice(self): + return self.passage_dice if self.round.draw.get_state() == 'DICE_SELECT_POULES' else self.choice_dice + @property def penalty_int(self): return max(0, len(self.rejected) - (settings.PROBLEM_COUNT - 5)) diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 9755e2e..ad264a1 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: TFJM\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-26 11:05+0200\n" +"POT-Creation-Date: 2023-03-28 21:55+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Emmy D'Anello \n" "Language-Team: LANGUAGE \n" @@ -21,7 +21,7 @@ msgstr "" msgid "API" msgstr "API" -#: draw/apps.py:10 +#: draw/apps.py:10 tfjm/templates/base.html:97 msgid "Draw" msgstr "Tirage au sort" @@ -61,22 +61,22 @@ msgstr "Vous avez déjà lancé le dé." msgid "It is not your turn." msgstr "Ce n'est pas votre tour." -#: draw/consumers.py:191 draw/consumers.py:360 draw/consumers.py:399 -#: draw/consumers.py:526 +#: draw/consumers.py:191 draw/consumers.py:362 draw/consumers.py:406 +#: draw/consumers.py:535 msgid "This is not the time for this." msgstr "Ce n'est pas le moment pour cela." -#: draw/consumers.py:224 draw/consumers.py:323 +#: draw/consumers.py:227 draw/consumers.py:325 #, python-brace-format msgid "Dices from teams {teams} are identical. Please relaunch your dices." msgstr "" "Les dés des équipes {teams} sont identiques. Merci de relancer vos dés." -#: draw/consumers.py:258 +#: draw/consumers.py:261 msgid "Two pools are identical. Please relaunch your dices." msgstr "Deux poules sont identiques. Merci de relancer vos dés." -#: draw/consumers.py:598 +#: draw/consumers.py:607 msgid "This is only available for the final tournament." msgstr "Cela n'est possible que pour la finale." @@ -166,29 +166,33 @@ msgstr "numéro de passage" msgid "choose index" msgstr "numéro de choix" -#: draw/models.py:310 draw/models.py:326 participation/models.py:422 +#: draw/models.py:310 draw/models.py:333 participation/models.py:422 #: participation/models.py:576 #, python-brace-format msgid "Problem #{problem}" msgstr "Problème n°{problem}" -#: draw/models.py:314 draw/models.py:330 +#: draw/models.py:314 draw/models.py:337 msgid "accepted problem" msgstr "problème accepté" #: draw/models.py:321 -msgid "last dice" -msgstr "dernier dé" +msgid "passage dice" +msgstr "dé d'ordre passage" -#: draw/models.py:335 +#: draw/models.py:328 +msgid "choice dice" +msgstr "dé d'ordre de choix" + +#: draw/models.py:342 msgid "rejected problems" msgstr "problèmes rejetés" -#: draw/models.py:347 +#: draw/models.py:358 msgid "team draw" msgstr "tirage d'équipe" -#: draw/models.py:348 +#: draw/models.py:359 msgid "team draws" msgstr "tirages d'équipe" @@ -765,12 +769,12 @@ msgstr "" #: participation/templates/participation/create_team.html:11 #: participation/templates/participation/tournament_form.html:14 -#: tfjm/templates/base.html:241 +#: tfjm/templates/base.html:248 msgid "Create" msgstr "Créer" #: participation/templates/participation/join_team.html:11 -#: tfjm/templates/base.html:236 +#: tfjm/templates/base.html:243 msgid "Join" msgstr "Rejoindre" @@ -1154,7 +1158,7 @@ msgid "Are you sure that you want to leave this team?" msgstr "Êtes-vous sûr·e de vouloir quitter cette équipe ?" #: participation/templates/participation/team_list.html:6 -#: tfjm/templates/base.html:229 +#: tfjm/templates/base.html:236 msgid "All teams" msgstr "Toutes les équipes" @@ -1237,7 +1241,7 @@ msgid "Add pool" msgstr "Ajouter une poule" #: participation/templates/participation/tournament_list.html:6 -#: tfjm/templates/base.html:225 +#: tfjm/templates/base.html:232 msgid "All tournaments" msgstr "Tous les tournois" @@ -1254,7 +1258,7 @@ msgid "Templates:" msgstr "Modèles :" #: participation/views.py:44 tfjm/templates/base.html:73 -#: tfjm/templates/base.html:240 +#: tfjm/templates/base.html:247 msgid "Create team" msgstr "Créer une équipe" @@ -1267,7 +1271,7 @@ msgid "You are already in a team." msgstr "Vous êtes déjà dans une équipe." #: participation/views.py:89 tfjm/templates/base.html:78 -#: tfjm/templates/base.html:235 +#: tfjm/templates/base.html:242 msgid "Join team" msgstr "Rejoindre une équipe" @@ -1724,8 +1728,8 @@ msgid "Your password has been set. You may go ahead and log in now." msgstr "Votre mot de passe a été changé. Vous pouvez désormais vous connecter." #: registration/templates/registration/password_reset_complete.html:10 -#: tfjm/templates/base.html:126 tfjm/templates/base.html:245 -#: tfjm/templates/base.html:246 tfjm/templates/registration/login.html:7 +#: tfjm/templates/base.html:133 tfjm/templates/base.html:252 +#: tfjm/templates/base.html:253 tfjm/templates/registration/login.html:7 #: tfjm/templates/registration/login.html:8 #: tfjm/templates/registration/login.html:25 msgid "Log in" @@ -2140,35 +2144,35 @@ msgstr "Mon équipe" msgid "My participation" msgstr "Ma participation" -#: tfjm/templates/base.html:96 +#: tfjm/templates/base.html:103 msgid "Chat" msgstr "Chat" -#: tfjm/templates/base.html:100 +#: tfjm/templates/base.html:107 msgid "Administration" msgstr "Administration" -#: tfjm/templates/base.html:108 +#: tfjm/templates/base.html:115 msgid "Search…" msgstr "Chercher…" -#: tfjm/templates/base.html:117 +#: tfjm/templates/base.html:124 msgid "Return to admin view" msgstr "Retourner à l'interface administrateur⋅rice" -#: tfjm/templates/base.html:122 +#: tfjm/templates/base.html:129 msgid "Register" msgstr "S'inscrire" -#: tfjm/templates/base.html:138 +#: tfjm/templates/base.html:145 msgid "My account" msgstr "Mon compte" -#: tfjm/templates/base.html:143 +#: tfjm/templates/base.html:150 msgid "Log out" msgstr "Déconnexion" -#: tfjm/templates/base.html:161 +#: tfjm/templates/base.html:168 #, python-format msgid "" "Your email address is not validated. Please click on the link you received " @@ -2179,15 +2183,15 @@ msgstr "" "avez reçu par mail. Vous pouvez renvoyer un mail en cliquant sur ce lien." -#: tfjm/templates/base.html:183 +#: tfjm/templates/base.html:190 msgid "Contact us" msgstr "Nous contacter" -#: tfjm/templates/base.html:210 +#: tfjm/templates/base.html:217 msgid "About" msgstr "À propos" -#: tfjm/templates/base.html:232 +#: tfjm/templates/base.html:239 msgid "Search results" msgstr "Résultats de la recherche" @@ -2228,6 +2232,9 @@ msgstr "Résultats" msgid "No results found." msgstr "Aucun résultat." +#~ msgid "last dice" +#~ msgstr "dernier dé" + #~ msgid "Problem" #~ msgstr "Problème"