From c21e6254180d4e22318a05284828e72f5f79479b Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 12 Mar 2024 14:42:43 +0100 Subject: [PATCH] Fixes --- padelclub_backend/settings.py | 4 +-- tournaments/models/match.py | 31 ++++++++++++++----- tournaments/models/team_registration.py | 26 +++++++++++++++- tournaments/models/team_score.py | 8 +++-- tournaments/models/tournament.py | 10 +++--- tournaments/static/tournaments/css/style.css | 12 ++++++- .../tournaments/broadcasted_matches.html | 2 +- .../templates/tournaments/match_cell.html | 14 ++++----- .../templates/tournaments/summon_row.html | 7 ++--- 9 files changed, 81 insertions(+), 33 deletions(-) diff --git a/padelclub_backend/settings.py b/padelclub_backend/settings.py index 955744f..636d46a 100644 --- a/padelclub_backend/settings.py +++ b/padelclub_backend/settings.py @@ -109,9 +109,9 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/4.1/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'fr' -TIME_ZONE = 'Europe/Paris' +TIME_ZONE = 'CET' USE_I18N = True diff --git a/tournaments/models/match.py b/tournaments/models/match.py index a1fd103..70106a9 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -33,11 +33,20 @@ class Match(models.Model): items = [] if self.round: items.append(self.round.name()) + items.append(f" #{self.index}") elif self.group_stage: items.append(self.group_stage.name()) - items.append(f"{self.index}") + items.append(f"Match #{self.index}") return " ".join(items) + def stage_name(self): + if self.round: + return self.round.name() + elif self.group_stage: + return self.group_stage.name() + else: + return '--' + def player_names(self): return map(lambda ts: ts.player_names(), self.team_scores.all()) @@ -48,6 +57,18 @@ class Match(models.Model): return '' # return str(self.start_date) #.strftime("%H:%M") + def time_indication(self): + if self.end_date: + return self.formatted_duration() + elif self.start_date: + if self.started(): + return self.formatted_duration() + else: + start = self.start_date.strftime("%H:%M") + return f"Prévu à {start}" + else: + return 'À venir...' + def current_duration(self): if self.end_date: return (self.end_date - self.start_date).total_seconds() @@ -62,12 +83,6 @@ class Match(models.Model): else: return False - def durationPrefix(self): - if self.current_duration() > 0: - return "Temps de jeu" - else: - return "Démarrage prévu dans" - def formatted_duration(self): _seconds = self.current_duration() @@ -88,7 +103,7 @@ class Match(models.Model): def live_match(self): title = self.name() date = self.formatted_start_date() - duration = self.formatted_duration() + duration = self.time_indication() court = "" if self.court: court = f"Terrain {self.court}" diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index e8ba4aa..e7974a2 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -1,5 +1,6 @@ from django.db import models -from . import Tournament, GroupStage +from django.db.models.sql.query import Q +from . import Tournament, GroupStage, Match import uuid class TeamRegistration(models.Model): @@ -33,6 +34,29 @@ class TeamRegistration(models.Model): else: return "no players" + def next_match(self): + all_matches = map(lambda ts: ts.match, self.teamscore_set.all()) + all_matches = sorted(all_matches, key=lambda m: m.start_date) + matches = [m for m in all_matches if m.end_date is None] + if matches: + return matches[0] + else: + return all_matches[0] + + # match = self.first_match(False) + # if match: + # return match + # else: + # return self.first_match(True) + + # def first_match(self, completed): + # q_base = Q(team_scores__team_registration==self) + # q = Q(end_date__isnull=not completed, start_date__isnull=False) + # q_round = Q(round__tournament=self.tournament) + # q_group_stage = Q(group_stage__tournament=self.tournament) + # matches = Match.objects.filter(q_base, q, q_round | q_group_stage).order_by('start_date') + # return matches[0] + def next_stage(self): matches = map(lambda ts: ts.match, self.teamscore_set.all()) matches = [m for m in matches if m.group_stage is None] diff --git a/tournaments/models/team_score.py b/tournaments/models/team_score.py index 519f39d..028d627 100644 --- a/tournaments/models/team_score.py +++ b/tournaments/models/team_score.py @@ -27,7 +27,9 @@ class TeamScore(models.Model): return names def scores_array(self): + scores = [] if self.score: - return [int(x) for x in self.score.split(',')] - else: - return [] + scores = [x for x in self.score.split(',')] + if self.walk_out == 1: + scores.insert(0, 'WO') + return scores diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 8086697..21c0089 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -56,12 +56,12 @@ class Tournament(models.Model): summons = [] for team_registration in self.teamregistration_set.all(): - call_date = team_registration.call_date - if call_date: + next_match = team_registration.next_match() + if next_match: names = team_registration.team_names() - stage = team_registration.next_stage() + stage = next_match.stage_name() weight = team_registration.weight() - summon = TeamSummon(names, call_date, weight, stage, team_registration.logo) + summon = TeamSummon(names, next_match.start_date, weight, stage, team_registration.logo) summons.append(summon) return summons @@ -75,7 +75,7 @@ class Tournament(models.Model): for match in round.match_set.all(): matches.append(match) - # matches = [m for m in matches if m.broadcasted==True] + matches = [m for m in matches if m.broadcasted==True] return map(lambda match: match.live_match(), matches) diff --git a/tournaments/static/tournaments/css/style.css b/tournaments/static/tournaments/css/style.css index a926560..770265f 100644 --- a/tournaments/static/tournaments/css/style.css +++ b/tournaments/static/tournaments/css/style.css @@ -182,6 +182,9 @@ tr { .names { /* width: 70%; */ } +.team-names-box { + height: 60px; +} .scores { vertical-align: middle; @@ -348,7 +351,7 @@ tr { .flex-row { display: flex; justify-content: space-between; - height: 29px; + /* height: 29px; */ align-items: center; /* vertical-align: middle; */ } @@ -421,6 +424,13 @@ tr { padding: 5px 0px; } +.table-row-4-colums { + display: grid; + grid-template-columns: 1px auto 50px 70px 130px; /* first column is a hack */ + align-items: center; /* Vertically center the content within each column */ + padding: 5px 0px; +} + .table-row-5-colums { display: grid; grid-template-columns: 60px auto 50px 70px 130px; diff --git a/tournaments/templates/tournaments/broadcasted_matches.html b/tournaments/templates/tournaments/broadcasted_matches.html index 4fd2c00..2d05116 100644 --- a/tournaments/templates/tournaments/broadcasted_matches.html +++ b/tournaments/templates/tournaments/broadcasted_matches.html @@ -37,7 +37,7 @@ setInterval(() => { this.retrieveMatches() this.active = this.active === this.paginatedMatches.length ? 1 : this.active+1 - }, 3000) + }, 30000) } }" x-init="loop()"> diff --git a/tournaments/templates/tournaments/match_cell.html b/tournaments/templates/tournaments/match_cell.html index 3454d57..37e4746 100644 --- a/tournaments/templates/tournaments/match_cell.html +++ b/tournaments/templates/tournaments/match_cell.html @@ -5,21 +5,21 @@
- +
{% for team in match.teams %} -
- {% if team.image %} +
+ -
+
{% for name in team.names %}
{{ name }} @@ -42,8 +42,8 @@
-
- +
+
diff --git a/tournaments/templates/tournaments/summon_row.html b/tournaments/templates/tournaments/summon_row.html index 8b934b8..8c754b6 100644 --- a/tournaments/templates/tournaments/summon_row.html +++ b/tournaments/templates/tournaments/summon_row.html @@ -1,10 +1,7 @@ {% load static %} -
-
- -
- +
+
{% for name in summon.names %}
{{ name }}