Adds tournament info page + UI improvements

clubs
Laurent 1 year ago
parent 86aaf98c47
commit 38b3239d91
  1. 9
      tournaments/models/club.py
  2. 7
      tournaments/models/match.py
  3. 12
      tournaments/models/tournament.py
  4. 8
      tournaments/templates/tournaments/broadcast/broadcasted_group_stage.html
  5. 4
      tournaments/templates/tournaments/broadcast/broadcasted_match.html
  6. 2
      tournaments/templates/tournaments/broadcast/broadcasted_ranking.html
  7. 2
      tournaments/templates/tournaments/broadcast/broadcasted_summon.html
  8. 6
      tournaments/templates/tournaments/group_stage_cell.html
  9. 3
      tournaments/templates/tournaments/navigation_tournament.html
  10. 36
      tournaments/templates/tournaments/test_websocket.html
  11. 36
      tournaments/templates/tournaments/tournament_info.html
  12. 3
      tournaments/urls.py
  13. 6
      tournaments/utils/extensions.py
  14. 16
      tournaments/views.py

@ -34,3 +34,12 @@ class Club(models.Model):
return f"Terrain {index + 1}"
return ""
def has_address(self):
return self.address and self.zip_code and self.city
def city_zipcode(self):
if self.has_address():
return f"{self.zip_code} {self.city}"
else:
return ""

@ -185,9 +185,10 @@ class Match(models.Model):
date = self.formatted_start_date()
duration = self.time_indication()
court = self.court_name(self.court_index)
group_stage_name = self.group_stage.display_name()
ended = self.end_date is not None
livematch = LiveMatch(title, date, duration, court, self.started(), ended)
livematch = LiveMatch(title, date, duration, court, self.started(), ended, group_stage_name)
for team_score in self.sorted_team_scores():
if team_score.team_registration:
@ -249,7 +250,7 @@ class Team:
}
class LiveMatch:
def __init__(self, title, date, duration, court, started, ended):
def __init__(self, title, date, duration, court, started, ended, group_stage_name):
self.title = title
self.date = date
self.teams = []
@ -258,6 +259,7 @@ class LiveMatch:
self.started = started
self.ended = ended
self.has_walk_out = False
self.group_stage_name = group_stage_name
def add_team(self, team):
self.teams.append(team)
@ -274,6 +276,7 @@ class LiveMatch:
"started": self.started,
"ended": self.ended,
"has_walk_out": self.has_walk_out,
"group_stage_name": self.group_stage_name,
}
def show_duration(self):

@ -9,6 +9,7 @@ from django.utils import timezone, formats
from datetime import datetime, timedelta
from .. import config_local
from ..utils.cryptography import decrypt_aes_gcm
from ..utils.extensions import plural_format
class TeamSortingType(models.IntegerChoices):
RANK = 1, 'Rank'
@ -595,7 +596,7 @@ class Tournament(models.Model):
return True
bracket_matches = self.bracket_matches()
if len(bracket_matches) == 0:
return self.display_group_stages
return self.display_group_stages()
if self.publish_brackets:
return True
@ -641,6 +642,15 @@ class Tournament(models.Model):
def is_build_and_not_empty(self):
return (len(self.groupstage_set.all()) > 0 or len(self.round_set.all()) > 0) and len(self.teamregistration_set.all()) >= 4
def day_duration_formatted(self):
return plural_format("jour", self.day_duration)
def has_club_address(self):
if self.event.club:
return self.event.club.has_address()
else:
return False
class MatchGroup:
def __init__(self, name, matches):
self.name = name

@ -1,7 +1,7 @@
<div class="dark_bubble">
<div class="flex-row">
<label class="left-label matchtitle winner"><span x-text="group_stage.title"></span></label>
<label class="left-label matchtitle winner"><span x-text="group_stage.group_stage_name"></span> <span x-text="group_stage.title"></span></label>
</div>
<template x-for="i in group_stage.teams.length">
@ -32,13 +32,13 @@
<div class="flex-right">
<div x-show="group_stage.teams[i-1].match_count == 0">
<div class="score ws"><span x-text="group_stage.teams[i-1].weight"></span></div>
<div class="score ws numbers"><span x-text="group_stage.teams[i-1].weight"></span></div>
</div>
<div x-show="group_stage.teams[i-1].match_count > 0">
<div class="center">
<div class="score ws"><span x-text="group_stage.teams[i-1].win_loss"></span></div>
<div class="ws"><span x-text="group_stage.teams[i-1].diff"></span></div>
<div class="score ws numbers"><span x-text="group_stage.teams[i-1].win_loss"></span></div>
<div class="ws numbers"><span x-text="group_stage.teams[i-1].diff"></span></div>
</div>
</div>

@ -1,7 +1,9 @@
<div class="bubble">
<div class="flex-row">
<label class="left-label matchtitle"><span x-text="match.title"></span></label>
<label class="left-label matchtitle">
<span x-text="match.group_stage_name"></span><span x-show="match.group_stage_name"> :</span> <span x-text="match.title"></span>
</label>
<!-- <label class="right-label info"><span x-text="match.date"></span></label> -->
</div>

@ -11,7 +11,7 @@
</template>
</div>
<div class="table-cell right horizontal-padding"><span x-text="ranking.points"></div>
<div class="table-cell right horizontal-padding numbers"><span x-text="ranking.points"></div>
</div>
<div x-show="index < column.length - 1">
<hr/>

@ -8,7 +8,7 @@
</template>
</div>
<div class="table-cell center"><span x-text="summon.weight"></span></div>
<div class="table-cell center numbers"><span x-text="summon.weight"></span></div>
<div class="table-cell large center"><span x-text="summon.date"></span></div>
<div class="table-cell"><div class="mybox center"><span x-text="summon.stage"></span></div></div>
</div>

@ -25,12 +25,12 @@
{% if tournament.hide_weight %}
<div class="score ws"></div>
{% else %}
<div class="score ws">{{ team.weight }}</div>
<div class="score ws numbers">{{ team.weight }}</div>
{% endif %}
{% else %}
<div class="center">
<div class="score ws">{{ team.wins_losses }}</div>
<div class="ws">{{ team.formatted_diff }}</div>
<div class="score ws numbers">{{ team.wins_losses }}</div>
<div class="ws numbers">{{ team.formatted_diff }}</div>
</div>
{% endif %}
</div>

@ -1,4 +1,7 @@
<nav class="margin10">
<a href="{% url 'tournament-info' tournament.id %}" class="topmargin5">Informations</a>
{% if tournament.display_matches %}
<a href="{% url 'tournament' tournament.id %}" class="topmargin5">Matches</a>
{% endif %}

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title>WebSocket Test</title>
</head>
<body>
<h1>WebSocket Test</h1>
<input id="messageInput" type="text">
<button onclick="sendMessage()">Send</button>
<div id="messages"></div>
<script>
const chatSocket = new WebSocket(
'ws://' + window.location.host + '/ws/sync/'
);
chatSocket.onmessage = function(e) {
const data = JSON.parse(e.data);
document.querySelector('#messages').innerHTML += '<p>' + data.message + '</p>';
};
chatSocket.onclose = function(e) {
console.error('Chat socket closed unexpectedly');
};
function sendMessage() {
const messageInputDom = document.querySelector('#messageInput');
const message = messageInputDom.value;
chatSocket.send(JSON.stringify({
'message': message
}));
messageInputDom.value = '';
}
</script>
</body>
</html>

@ -0,0 +1,36 @@
{% extends 'tournaments/base.html' %}
{% block head_title %}Convocations du {{ tournament.display_name }}{% endblock %}
{% block first_title %}{{ tournament.event.display_name }}{% endblock %}
{% block second_title %}{{ tournament.display_name }}{% endblock %}
{% block content %}
{% load static %}
{% include 'tournaments/navigation_tournament.html' %}
<div class="grid-x">
<div class="cell medium-6 large-6 my-block">
<h1 class="club my-block topmargin20">{{ tournament.display_name }} {{ tournament.get_federal_age_category_display}}</h1 >
<div class="bubble">
<p>
<div class="semibold">{{ tournament.start_date }}</div>
<div>{{ tournament.day_duration_formatted }}</div>
</p>
<p>
<div class="semibold">{{ tournament.event.club.name }}</div>
{% if tournament.has_club_address %}
<div>{{ tournament.event.club.address }}</div>
<div>{{ tournament.event.club.city_zipcode }}</div>
{% endif %}
</p>
</div>
</div>
</div>
{% endblock %}

@ -12,6 +12,7 @@ urlpatterns = [
include([
path('', views.tournament, name='tournament'),
path('teams/', views.tournament_teams, name='tournament-teams'),
path('info/', views.tournament_info, name='tournament-info'),
path('summons/', views.tournament_summons, name='tournament-summons'),
path('broadcast/summons/', views.tournament_broadcasted_summons, name='broadcasted-summons'),
path('summons/json/', views.tournament_summons_json, name='tournament-summons-json'),
@ -31,6 +32,6 @@ urlpatterns = [
path('players/', views.players, name='players'),
path('activate/<uidb64>/<token>/', views.activate, name='activate'),
path('download/', views.download, name='download'),
path('apns/', views.test_apns, name='test-apns')
path('apns/', views.test_apns, name='test-apns'),
]

@ -2,3 +2,9 @@ def format_seconds(seconds):
hours = int(seconds / 3600)
minutes = int((seconds % 3600) / 60)
return f"{hours:02d}h{minutes:02d}min"
def plural_format(label, count):
if count < 2:
return label
else:
return f"{count} {label}s"

@ -72,6 +72,12 @@ def future_tournaments(club_id):
tournaments = tournaments_query(Q(end_date__isnull=True, start_date__gt=tomorrow), club_id, True)
return [t for t in tournaments if t.display_tournament()]
def tournament_info(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id)
return render(request, 'tournaments/tournament_info.html', {
'tournament': tournament,
})
def tournaments(request):
filter = int(request.GET.get('filter'))
@ -123,12 +129,19 @@ def tournament(request, tournament_id):
rounds = tournament.round_set.filter(parent=None).order_by('-index')
group_stages = tournament.groupstage_set.order_by('index')
print(len(match_groups))
print(len(rounds))
print(len(group_stages))
if len(match_groups) > 0:
return render(request, 'tournaments/matches.html', {
'tournament': tournament,
'rounds': rounds,
'group_stages': group_stages,
'match_groups': match_groups,
})
else:
return tournament_info(request, tournament_id)
def tournament_teams(request, tournament_id):
@ -292,3 +305,6 @@ def test_apns(request):
asyncio.run(send_push_notification(token.value, 'hello!'))
return HttpResponse('OK!')
def test_websocket(request):
return render(request, 'tournaments/test_websocket.html')

Loading…
Cancel
Save