fix prog display

sync_v2
Raz 6 months ago
parent aaebde94b1
commit d468fef6af
  1. 4
      tournaments/models/match.py
  2. 2
      tournaments/models/tournament.py
  3. 23
      tournaments/views.py

@ -307,6 +307,10 @@ class Match(SideStoreModel):
timezone = self.tournament().timezone()
return self.start_date.astimezone(timezone)
def local_planned_start_date(self):
timezone = self.tournament().timezone()
return self.planned_start_date.astimezone(timezone)
def formatted_start_date(self):
if self.start_date:
local_start = self.local_start_date()

@ -1997,7 +1997,7 @@ class Tournament(BaseModel):
# Sort matches by court if available
matches.sort(key=lambda m: (m.court_index if m.court_index is not None else 999))
local_date = matches[0].local_start_date()
local_date = matches[0].local_planned_start_date()
formatted_name = formats.date_format(local_date, format='l j F à H:i').capitalize()
mg = self.create_match_group(
name=formatted_name,

@ -1039,13 +1039,34 @@ def tournament_prog(request, tournament_id):
# Format days for template
formatted_days = [day.strftime('%Y-%m-%d') for day in days]
# If no day is requested, check if today's date is in the list of days
selected_day = day_param
if not selected_day and days:
today = timezone.now()
today_str = today.strftime('%Y-%m-%d')
# Check if today's date exists in formatted_days
if today_str in formatted_days:
selected_day = today_str
else:
# Default to first day if today is not in the list
if tournament.has_ended():
selected_day = days[-1].strftime('%Y-%m-%d')
else:
selected_day = days[0].strftime('%Y-%m-%d')
else:
if tournament.has_ended():
selected_day = selected_day or (days[-1].strftime('%Y-%m-%d') if days else None)
else:
selected_day = selected_day or (days[0].strftime('%Y-%m-%d') if days else None)
context = {
'tournament': tournament,
'prog_mode': True,
'match_groups': match_groups,
'days': days,
'formatted_days': formatted_days,
'selected_day': day_param or (days[0].strftime('%Y-%m-%d') if days else None)
'selected_day': selected_day
}
return render(request, 'tournaments/prog.html', context)

Loading…
Cancel
Save