diff --git a/draw/consumers.py b/draw/consumers.py index ac0ab77..e39bd7f 100644 --- a/draw/consumers.py +++ b/draw/consumers.py @@ -171,11 +171,14 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): participation = await Participation.objects\ .filter(teamdraw__round=self.tournament.draw.current_round, teamdraw__passage_dice__isnull=True).prefetch_related('team').afirst() - trigram = participation.team.trigram else: participation = await Participation.objects.filter(team__participants=self.registration)\ .prefetch_related('team').aget() - trigram = participation.team.trigram + + if participation is None: + return await self.alert(_("This is not the time for this."), 'danger') + + trigram = participation.team.trigram team_draw = await TeamDraw.objects.filter(participation=participation, round_id=self.tournament.draw.current_round_id).aget() @@ -293,12 +296,13 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): await self.channel_layer.group_send(f"volunteer-{self.tournament.id}", {'type': 'draw.dice_visibility', 'visible': True}) - await self.channel_layer.group_send(f"tournament-{self.tournament.id}", - {'type': 'draw.send_poules', - 'round': self.tournament.draw.current_round}) + # First send the second pool to have the good team order await self.channel_layer.group_send(f"tournament-{self.tournament.id}", {'type': 'draw.send_poules', 'round': await self.tournament.draw.round_set.filter(number=2).aget()}) + await self.channel_layer.group_send(f"tournament-{self.tournament.id}", + {'type': 'draw.send_poules', + 'round': self.tournament.draw.current_round}) await self.channel_layer.group_send(f"tournament-{self.tournament.id}", {'type': 'draw.set_info', 'draw': self.tournament.draw}) @@ -518,7 +522,19 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): f"tournament-{self.tournament.id}", {'type': 'draw.dice', 'team': participation.team.trigram, 'result': None}) - await self.channel_layer.group_send(f"team-{participation.team.trigram}", + # Reorder dices + await self.channel_layer.group_send(f"tournament-{self.tournament.id}", + {'type': 'draw.send_poules', + 'round': r2}) + + # The passage order for the second round is already determined by the first round + # Start the first pool of the second round + p1: Pool = await r2.pool_set.filter(letter=1).aget() + r2.current_pool = p1 + await sync_to_async(r2.save)() + + async for td in p1.teamdraw_set.prefetch_related('participation__team').all(): + await self.channel_layer.group_send(f"team-{td.participation.team.trigram}", {'type': 'draw.dice_visibility', 'visible': True}) await self.channel_layer.group_send(f"volunteer-{self.tournament.id}", {'type': 'draw.dice_visibility', 'visible': True})