diff --git a/tournaments/models/match.py b/tournaments/models/match.py index ea70838..a422a72 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -389,7 +389,7 @@ class Match(models.Model): ended = self.end_date is not None live_format = "Format " + FederalMatchCategory(self.format).format_label_short - livematch = LiveMatch(title, date, time_indication, court, self.started(), ended, group_stage_name, live_format) + livematch = LiveMatch(title, date, time_indication, court, self.started(), ended, group_stage_name, live_format, self.start_date, self.court_index) for team in self.live_teams(): livematch.add_team(team) @@ -446,7 +446,7 @@ class Team: } class LiveMatch: - def __init__(self, title, date, time_indication, court, started, ended, group_stage_name, format): + def __init__(self, title, date, time_indication, court, started, ended, group_stage_name, format, start_date, court_index): self.title = title self.date = date self.teams = [] @@ -457,6 +457,8 @@ class LiveMatch: self.has_walk_out = False self.group_stage_name = group_stage_name self.format = format + self.start_date = start_date + self.court_index = court_index def add_team(self, team): self.teams.append(team) @@ -474,7 +476,9 @@ class LiveMatch: "ended": self.ended, "has_walk_out": self.has_walk_out, "group_stage_name": self.group_stage_name, - "format": self.format + "format": self.format, + "start_date": self.start_date, + "court_index": self.court_index } def show_time_indication(self): diff --git a/tournaments/templates/tournaments/prog.html b/tournaments/templates/tournaments/prog.html new file mode 100644 index 0000000..44baf45 --- /dev/null +++ b/tournaments/templates/tournaments/prog.html @@ -0,0 +1,40 @@ +{% extends 'tournaments/base.html' %} + +{% block head_title %}Matchs du {{ tournament.display_name }}{% endblock %} +{% block first_title %}{{ tournament.event.display_name }}{% endblock %} +{% block second_title %}{{ tournament.display_name }}{% endblock %} + +{% if tournament.display_matches %} +{% block content %} + +{% include 'tournaments/navigation_tournament.html' %} + +{% if tournament.display_matches or tournament.display_group_stages %} + + {% regroup match_groups.matches by start_date|date:"l d F Y" as matches_by_date %} + + {% for date in matches_by_date %} + + {% regroup date.list by start_date|date:"H:i" as matches_by_hour %} + + {% for hour_group in matches_by_hour %} +

{{ date.grouper }} {{ hour_group.grouper }}

+ + {% regroup hour_group.list by court_index as matches_by_court %} + +
+ {% for court in matches_by_court|dictsort:"grouper" %} + {% for match_data in court.list %} + {% with match=match_data.match %} + {% include 'tournaments/match_cell.html' %} + {% endwith %} + {% endfor %} + {% endfor %} +
+ {% endfor %} + {% endfor %} + + +{% endif %} +{% endblock %} +{% endif %} diff --git a/tournaments/urls.py b/tournaments/urls.py index 1be64d4..84a1763 100644 --- a/tournaments/urls.py +++ b/tournaments/urls.py @@ -17,6 +17,7 @@ urlpatterns = [ path('', views.tournament, name='tournament'), path('teams/', views.tournament_teams, name='tournament-teams'), path('info/', views.tournament_info, name='tournament-info'), + path('prog/', views.tournament_prog, name='tournament-prog'), path('summons/', views.tournament_summons, name='tournament-summons'), path('broadcast/summons/', views.tournament_broadcasted_summons, name='broadcasted-summons'), path('summons/json/', views.tournament_summons_json, name='tournament-summons-json'), diff --git a/tournaments/views.py b/tournaments/views.py index 936d89a..afe74de 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -954,6 +954,33 @@ def team_details(request, tournament_id, team_id): 'debug': False # Set to False in production }) +def tournament_prog(request, tournament_id): + tournament = get_object_or_404(Tournament, id=tournament_id) + + # Get matches from all_groups + match_groups = tournament.all_groups(broadcasted=False) + + # Flatten matches and add necessary attributes + all_matches = [] + for group in match_groups: + for match in group.matches: + if match.start_date: # Only include matches with start dates + all_matches.append({ + 'start_date': match.start_date, + 'court_index': match.court_index, + # Add other match attributes needed for match_cell.html + 'match': match + }) + + # Sort matches by date and court + all_matches.sort(key=lambda x: (x['start_date'], x['court_index'] or 999)) + + context = { + 'tournament': tournament, + 'match_groups': {'matches': all_matches} + } + return render(request, 'tournaments/prog.html', context) + class UserListExportView(LoginRequiredMixin, View): def get(self, request, *args, **kwargs): users = CustomUser.objects.order_by('date_joined')