diff --git a/tournaments/models/match.py b/tournaments/models/match.py index 36ca3ac..9caada4 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -217,10 +217,13 @@ class Match(models.Model): # timezoned_datetime = timezone.localtime(self.start_date) timezone = self.tournament().timezone() local_start = self.start_date.astimezone(timezone) + time_format ='l H:i' + if self.tournament().day_duration >= 7: + time_format = 'l d M à H:i' if self.confirmed: - return formats.date_format(local_start, format='l H:i') + return formats.date_format(local_start, format=time_format) else: - return f"Estimée : {formats.date_format(local_start, format='l H:i')}" + return f"Estimée : {formats.date_format(local_start, format=time_format)}" else: return 'À venir...' diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index 79cb454..709c61f 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -100,4 +100,5 @@ class TeamRegistration(models.Model): if self.call_date: return self.call_date.astimezone(timezone) else: + print("no date") return None diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index d8782a0..36627ff 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -1,3 +1,4 @@ +from time import daylight from zoneinfo import ZoneInfo from django.db import models from typing import TYPE_CHECKING @@ -232,15 +233,16 @@ class Tournament(models.Model): def team_summons(self): summons = [] - print('>>> team_summons') if self.supposedly_in_progress() and self.end_date is None: + print('>>> team_summons supposedly_in_progress') for team in self.teams(False): names = team.names stage = team.stage weight = team.weight - summon = TeamSummon(names, team.date, weight, stage, "", team.image) + summon = TeamSummon(names, team.date, weight, stage, "", team.image, self.day_duration) summons.append(summon) else: + print('>>> team_summons') for team_registration in self.teamregistration_set.all(): if team_registration.is_valid_for_summon(): next_match = team_registration.next_match() @@ -248,7 +250,7 @@ class Tournament(models.Model): names = team_registration.team_names() stage = next_match.summon_stage_name() weight = team_registration.weight - summon = TeamSummon(names, next_match.local_start_date(), weight, stage, next_match.court_name(next_match.court_index), team_registration.logo) + summon = TeamSummon(names, next_match.local_start_date(), weight, stage, next_match.court_name(next_match.court_index), team_registration.logo, self.day_duration) summons.append(summon) summons.sort(key=lambda s: (s.date is None, s.date or datetime.min)) @@ -484,7 +486,21 @@ class Tournament(models.Model): def create_match_group(self, name, matches): matches = list(matches) live_matches = [match.live_match() for match in matches] - return MatchGroup(name, live_matches) + # Filter out matches that have a start_date of None + valid_matches = [match for match in matches if match.start_date is not None] + + formatted_schedule = '' + if valid_matches and self.day_duration >= 7: + # Find the first match by start date + first_match = min(valid_matches, key=lambda match: match.start_date) + + # Format the date + timezone = first_match.tournament().timezone() + local_start = first_match.start_date.astimezone(timezone) + time_format = 'l d M' + formatted_schedule = f" - {formats.date_format(local_start, format=time_format)}" + + return MatchGroup(name, live_matches, formatted_schedule) def live_group_stages(self): group_stages = self.get_computed_group_stage() @@ -855,28 +871,33 @@ class Tournament(models.Model): return True class MatchGroup: - def __init__(self, name, matches): + def __init__(self, name, matches, formatted_schedule): self.name = name self.matches = matches + self.formatted_schedule = formatted_schedule def add_match(self, match): self.matches.append(match) def add_matches(self, matches): - self.matches = matches + self.matches = matches class TeamSummon: - def __init__(self, names, date, weight, stage, court, image): + def __init__(self, names, date, weight, stage, court, image, day_duration): self.names = names self.date = date self.weight = weight self.stage = stage self.court = court self.image = image + self.day_duration = day_duration def formatted_date(self): if self.date: - return formats.date_format(self.date, format='l H:i') + if self.day_duration >= 7: + return formats.date_format(self.date, format='l d M H:i') + else: + return formats.date_format(self.date, format='l H:i') else: return '' diff --git a/tournaments/templates/tournaments/matches.html b/tournaments/templates/tournaments/matches.html index 0f5090c..f93fc75 100644 --- a/tournaments/templates/tournaments/matches.html +++ b/tournaments/templates/tournaments/matches.html @@ -31,7 +31,7 @@ {% if match_group.matches %} -

{{ match_group.name }}

+

{{ match_group.name }}{{ match_group.formatted_schedule }}

{% for match in match_group.matches %}