bracket-feature
laurent 1 year ago
commit 9c58a4d859
  1. 7
      tournaments/models/match.py
  2. 1
      tournaments/models/team_registration.py
  3. 33
      tournaments/models/tournament.py
  4. 2
      tournaments/templates/tournaments/matches.html

@ -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...'

@ -100,4 +100,5 @@ class TeamRegistration(models.Model):
if self.call_date:
return self.call_date.astimezone(timezone)
else:
print("no date")
return None

@ -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,9 +871,10 @@ 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)
@ -866,16 +883,20 @@ class MatchGroup:
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:
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 ''

@ -31,7 +31,7 @@
{% if match_group.matches %}
<h1 class="club my-block topmargin20">{{ match_group.name }}</h1>
<h1 class="club my-block topmargin20">{{ match_group.name }}{{ match_group.formatted_schedule }}</h1>
<div class="grid-x">
{% for match in match_group.matches %}

Loading…
Cancel
Save