From 93a71fb56172022c0c1d570e607c662d9cad479c Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Wed, 22 Mar 2023 20:41:16 +0100 Subject: [PATCH] Fix errors and better tab usage Signed-off-by: Emmy D'Anello --- draw/consumers.py | 13 +- ...pool_letter_alter_round_number_and_more.py | 203 ++++++++++++++++++ draw/static/draw.js | 17 +- draw/templates/draw/tournament_content.html | 44 ++-- 4 files changed, 249 insertions(+), 28 deletions(-) create mode 100644 draw/migrations/0002_pool_size_alter_pool_letter_alter_round_number_and_more.py diff --git a/draw/consumers.py b/draw/consumers.py index 597b6f8..c6427af 100644 --- a/draw/consumers.py +++ b/draw/consumers.py @@ -71,16 +71,17 @@ class DrawConsumer(AsyncJsonWebsocketConsumer): .format(len=len(self.participations), sum=sum(fmt)), 'danger') draw = await sync_to_async(Draw.objects.create)(tournament=self.tournament) - r = await sync_to_async(Round.objects.create)(draw=draw, number=1) - for i, f in enumerate(fmt): - sync_to_async(Pool.objects.create)(round=r, letter=i + 1, size=f) - for participation in self.participations: - sync_to_async(TeamDraw.objects.create)(participation=participation) + for i in [1, 2]: + r = await sync_to_async(Round.objects.create)(draw=draw, number=i) + for j, f in enumerate(fmt): + await sync_to_async(Pool.objects.create)(round=r, letter=j + 1, size=f) + for participation in self.participations: + await sync_to_async(TeamDraw.objects.create)(participation=participation) await self.alert(_("Draw started!"), 'success') await self.channel_layer.group_send(f"tournament-{self.tournament.id}", - {'type': 'draw.start', 'fmt': fmt, 'draw': draw, 'round': r}) + {'type': 'draw.start', 'fmt': fmt, 'draw': draw}) async def draw_start(self, content): await self.alert(_("The draw for the tournament {tournament} will start.")\ diff --git a/draw/migrations/0002_pool_size_alter_pool_letter_alter_round_number_and_more.py b/draw/migrations/0002_pool_size_alter_pool_letter_alter_round_number_and_more.py new file mode 100644 index 0000000..898455b --- /dev/null +++ b/draw/migrations/0002_pool_size_alter_pool_letter_alter_round_number_and_more.py @@ -0,0 +1,203 @@ +# Generated by Django 4.1.7 on 2023-03-22 19:30 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("draw", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="pool", + name="size", + field=models.PositiveSmallIntegerField(default=3, verbose_name="size"), + preserve_default=False, + ), + migrations.AlterField( + model_name="pool", + name="letter", + field=models.PositiveSmallIntegerField( + choices=[(1, "A"), (2, "B"), (3, "C")], verbose_name="letter" + ), + ), + migrations.AlterField( + model_name="round", + name="number", + field=models.PositiveSmallIntegerField( + choices=[(1, "Round 1"), (2, "Round 2")], verbose_name="number" + ), + ), + migrations.AlterField( + model_name="teamdraw", + name="accepted", + field=models.PositiveSmallIntegerField( + choices=[ + (1, "Problem #1"), + (2, "Problem #2"), + (3, "Problem #3"), + (4, "Problem #4"), + (5, "Problem #5"), + (6, "Problem #6"), + (7, "Problem #7"), + (8, "Problem #8"), + ], + default=None, + null=True, + verbose_name="accepted problem", + ), + ), + migrations.AlterField( + model_name="teamdraw", + name="index", + field=models.PositiveSmallIntegerField( + choices=[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)], + default=None, + null=True, + verbose_name="index", + ), + ), + migrations.AlterField( + model_name="teamdraw", + name="last_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="last dice", + ), + ), + migrations.AlterField( + model_name="teamdraw", + name="pool", + field=models.ForeignKey( + default=None, + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="draw.pool", + verbose_name="pool", + ), + ), + migrations.AlterField( + model_name="teamdraw", + name="purposed", + field=models.PositiveSmallIntegerField( + choices=[ + (1, "Problem #1"), + (2, "Problem #2"), + (3, "Problem #3"), + (4, "Problem #4"), + (5, "Problem #5"), + (6, "Problem #6"), + (7, "Problem #7"), + (8, "Problem #8"), + ], + default=None, + null=True, + verbose_name="accepted problem", + ), + ), + ] diff --git a/draw/static/draw.js b/draw/static/draw.js index 0d624c7..2d097f2 100644 --- a/draw/static/draw.js +++ b/draw/static/draw.js @@ -4,6 +4,18 @@ const sockets = {} const messages = document.getElementById('messages') document.addEventListener('DOMContentLoaded', () => { + if (document.location.hash) { + document.querySelectorAll('button[data-bs-toggle="tab"]').forEach(elem => { + if ('#' + elem.innerText.toLowerCase() === document.location.hash.toLowerCase()) { + elem.click() + } + }) + } + + document.querySelectorAll('button[data-bs-toggle="tab"]').forEach( + elem => elem.addEventListener( + 'click', () => document.location.hash = '#' + elem.innerText.toLowerCase())) + for (let tournament of tournaments) { let socket = new WebSocket( 'ws://' + window.location.host + '/ws/draw/' + tournament.id + '/' @@ -24,9 +36,8 @@ document.addEventListener('DOMContentLoaded', () => { } function draw_start(data) { - fetch(`/draw/content/${tournament.id}/`).then(resp => resp.text()).then(text => { - document.getElementById(`tab-${tournament.id}-pane`).innerHTML = text - }) + document.getElementById(`banner-not-started-${tournament.id}`).classList.add('d-none') + document.getElementById(`draw-content-${tournament.id}`).classList.remove('d-none') } socket.addEventListener('message', e => { diff --git a/draw/templates/draw/tournament_content.html b/draw/templates/draw/tournament_content.html index c4f27c8..ebba86c 100644 --- a/draw/templates/draw/tournament_content.html +++ b/draw/templates/draw/tournament_content.html @@ -4,24 +4,30 @@ {% if tournament.draw %} Tirage lancé ! {% else %} -
- {% trans "The draw has not started yet." %} - {% if user.registration.is_volunteer %} -
-
-
- - - -
-
-
- {% endif %} -
{% endif %} + + + +
+ Tournoi commencé +