1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-26 06:22:22 +00:00

Fix errors and better tab usage

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2023-03-22 20:41:16 +01:00
parent bde3758c50
commit 93a71fb561
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
4 changed files with 249 additions and 28 deletions

View File

@ -71,16 +71,17 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
.format(len=len(self.participations), sum=sum(fmt)), 'danger') .format(len=len(self.participations), sum=sum(fmt)), 'danger')
draw = await sync_to_async(Draw.objects.create)(tournament=self.tournament) 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 in [1, 2]:
for i, f in enumerate(fmt): r = await sync_to_async(Round.objects.create)(draw=draw, number=i)
sync_to_async(Pool.objects.create)(round=r, letter=i + 1, size=f) 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: for participation in self.participations:
sync_to_async(TeamDraw.objects.create)(participation=participation) await sync_to_async(TeamDraw.objects.create)(participation=participation)
await self.alert(_("Draw started!"), 'success') await self.alert(_("Draw started!"), 'success')
await self.channel_layer.group_send(f"tournament-{self.tournament.id}", 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): async def draw_start(self, content):
await self.alert(_("The draw for the tournament {tournament} will start.")\ await self.alert(_("The draw for the tournament {tournament} will start.")\

View File

@ -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",
),
),
]

View File

@ -4,6 +4,18 @@ const sockets = {}
const messages = document.getElementById('messages') const messages = document.getElementById('messages')
document.addEventListener('DOMContentLoaded', () => { 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) { for (let tournament of tournaments) {
let socket = new WebSocket( let socket = new WebSocket(
'ws://' + window.location.host + '/ws/draw/' + tournament.id + '/' 'ws://' + window.location.host + '/ws/draw/' + tournament.id + '/'
@ -24,9 +36,8 @@ document.addEventListener('DOMContentLoaded', () => {
} }
function draw_start(data) { function draw_start(data) {
fetch(`/draw/content/${tournament.id}/`).then(resp => resp.text()).then(text => { document.getElementById(`banner-not-started-${tournament.id}`).classList.add('d-none')
document.getElementById(`tab-${tournament.id}-pane`).innerHTML = text document.getElementById(`draw-content-${tournament.id}`).classList.remove('d-none')
})
} }
socket.addEventListener('message', e => { socket.addEventListener('message', e => {

View File

@ -4,7 +4,10 @@
{% if tournament.draw %} {% if tournament.draw %}
Tirage lancé ! Tirage lancé !
{% else %} {% else %}
<div class="alert alert-warning">
{% endif %}
<div id="banner-not-started-{{ tournament.id }}" class="alert alert-warning{% if tournament.draw %} d-none{% endif %}">
{% trans "The draw has not started yet." %} {% trans "The draw has not started yet." %}
{% if user.registration.is_volunteer %} {% if user.registration.is_volunteer %}
@ -24,4 +27,7 @@
</form> </form>
{% endif %} {% endif %}
</div> </div>
{% endif %}
<div id="draw-content-{{ tournament.id }}" class="{% if not tournament.draw %}d-none{% endif %}">
Tournoi commencé
</div>