fix prog display

sync_v2
Raz 6 months ago
parent 4774a2d814
commit df245c55d4
  1. 70
      tournaments/models/tournament.py

@ -1984,38 +1984,48 @@ class Tournament(BaseModel):
sorted_days = sorted(list(days)) sorted_days = sorted(list(days))
# Create match groups for the selected day # Create match groups for the selected day
match_groups = [] match_groups = []
print(days)
if all: if all:
for selected_day in sorted_days: today = timezone.now().date()
# Group matches by hour if today not in days:
matches_by_hour = {} selected_day = sorted_days[0] if sorted_days else None
for match in matches_by_day[selected_day]: else:
local_time = timezone.localtime(match.planned_start_date) # Default to first day if today is not in the list
hour_key = local_time.strftime('%H:%M') if self.has_ended():
selected_day = sorted_days[-1]
if hour_key not in matches_by_hour: else:
matches_by_hour[hour_key] = [] selected_day = sorted_days[0]
matches_by_hour[hour_key].append(match) # Group matches by hour
matches_by_hour = {}
hide_teams = self.show_teams_in_prog == False for match in matches_by_day[selected_day]:
# Create match groups for each hour local_time = timezone.localtime(match.planned_start_date)
for hour, matches in sorted(matches_by_hour.items()): hour_key = local_time.strftime('%H:%M')
# Sort matches by court if available
matches.sort(key=lambda m: (m.court_index if m.court_index is not None else 999)) if hour_key not in matches_by_hour:
matches_by_hour[hour_key] = []
local_date = matches[0].local_planned_start_date()
formatted_name = formats.date_format(local_date, format='l j F à H:i').capitalize() matches_by_hour[hour_key].append(match)
mg = self.create_match_group(
name=formatted_name, hide_teams = self.show_teams_in_prog == False
matches=matches, # Create match groups for each hour
round_id=None, for hour, matches in sorted(matches_by_hour.items()):
round_index=None, # Sort matches by court if available
hide_teams=hide_teams, matches.sort(key=lambda m: (m.court_index if m.court_index is not None else 999))
event_mode=event_mode,
broadcast=broadcast local_date = matches[0].local_planned_start_date()
) formatted_name = formats.date_format(local_date, format='l j F à H:i').capitalize()
match_groups.append(mg) mg = self.create_match_group(
name=formatted_name,
matches=matches,
round_id=None,
round_index=None,
hide_teams=hide_teams,
event_mode=event_mode,
broadcast=broadcast
)
match_groups.append(mg)
return sorted_days, match_groups return sorted_days, match_groups
# If specific day requested, filter to that day # If specific day requested, filter to that day

Loading…
Cancel
Save