diff --git a/tournaments/models/match.py b/tournaments/models/match.py index 543fc6f..c45ac69 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.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() diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 15cce2b..d32ad48 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -2003,7 +2003,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, diff --git a/tournaments/views.py b/tournaments/views.py index 74e3fdb..b0f8a63 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -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)