add full date if day duration is more than 6 days

online_registration
Raz 1 year ago
parent 40a3d584a0
commit 072029b1b0
  1. 7
      tournaments/models/match.py
  2. 1
      tournaments/models/team_registration.py
  3. 37
      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) # timezoned_datetime = timezone.localtime(self.start_date)
timezone = self.tournament().timezone() timezone = self.tournament().timezone()
local_start = self.start_date.astimezone(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: if self.confirmed:
return formats.date_format(local_start, format='l H:i') return formats.date_format(local_start, format=time_format)
else: 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: else:
return 'À venir...' return 'À venir...'

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

@ -1,3 +1,4 @@
from time import daylight
from zoneinfo import ZoneInfo from zoneinfo import ZoneInfo
from django.db import models from django.db import models
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
@ -232,15 +233,16 @@ class Tournament(models.Model):
def team_summons(self): def team_summons(self):
summons = [] summons = []
print('>>> team_summons')
if self.supposedly_in_progress() and self.end_date is None: if self.supposedly_in_progress() and self.end_date is None:
print('>>> team_summons supposedly_in_progress')
for team in self.teams(False): for team in self.teams(False):
names = team.names names = team.names
stage = team.stage stage = team.stage
weight = team.weight 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) summons.append(summon)
else: else:
print('>>> team_summons')
for team_registration in self.teamregistration_set.all(): for team_registration in self.teamregistration_set.all():
if team_registration.is_valid_for_summon(): if team_registration.is_valid_for_summon():
next_match = team_registration.next_match() next_match = team_registration.next_match()
@ -248,7 +250,7 @@ class Tournament(models.Model):
names = team_registration.team_names() names = team_registration.team_names()
stage = next_match.summon_stage_name() stage = next_match.summon_stage_name()
weight = team_registration.weight 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.append(summon)
summons.sort(key=lambda s: (s.date is None, s.date or datetime.min)) 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): def create_match_group(self, name, matches):
matches = list(matches) matches = list(matches)
live_matches = [match.live_match() for match in 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): def live_group_stages(self):
group_stages = self.get_computed_group_stage() group_stages = self.get_computed_group_stage()
@ -855,28 +871,33 @@ class Tournament(models.Model):
return True return True
class MatchGroup: class MatchGroup:
def __init__(self, name, matches): def __init__(self, name, matches, formatted_schedule):
self.name = name self.name = name
self.matches = matches self.matches = matches
self.formatted_schedule = formatted_schedule
def add_match(self, match): def add_match(self, match):
self.matches.append(match) self.matches.append(match)
def add_matches(self, matches): def add_matches(self, matches):
self.matches = matches self.matches = matches
class TeamSummon: 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.names = names
self.date = date self.date = date
self.weight = weight self.weight = weight
self.stage = stage self.stage = stage
self.court = court self.court = court
self.image = image self.image = image
self.day_duration = day_duration
def formatted_date(self): def formatted_date(self):
if self.date: 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: else:
return '' return ''

@ -31,7 +31,7 @@
{% if match_group.matches %} {% 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"> <div class="grid-x">
{% for match in match_group.matches %} {% for match in match_group.matches %}

Loading…
Cancel
Save