diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index cc9d175..7bc7535 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -1192,6 +1192,61 @@ class Tournament(models.Model): self._being_deleted = True super().delete(*args, **kwargs) + def broadcasted_prog(self): + # Get matches from broadcasted_matches_and_group_stages + matches, _ = self.broadcasted_matches_and_group_stages() + + if not matches: + return [] + + # Get all unfinished matches with court assignments + active_matches = [ + m for m in matches + if m.end_date is None # Not finished + and m.court_index is not None + ] + + # Group matches by court + matches_by_court = {} + courts = set() + for match in active_matches: + if match.court_index not in matches_by_court: + matches_by_court[match.court_index] = [] + courts.add(match.court_index) + matches_by_court[match.court_index].append(match) + + # Sort courts and organize them into groups of 4 + sorted_courts = sorted(list(courts)) + court_groups = [sorted_courts[i:i+4] for i in range(0, len(sorted_courts), 4)] + + ordered_matches = [] + # For each group of up to 4 courts + for court_group in court_groups: + # First row: current/next match for each court + for court in court_group: + if court in matches_by_court and matches_by_court[court]: + ordered_matches.append(matches_by_court[court][0]) + else: + ordered_matches.append(None) # Empty space + + # Second row: next match for each court + for court in court_group: + if court in matches_by_court and len(matches_by_court[court]) > 1: + ordered_matches.append(matches_by_court[court][1]) + else: + ordered_matches.append(None) # Empty space + + # Add unassigned matches at the end if needed + unassigned_matches = [ + m for m in matches + if m.end_date is None and m.court_index is None + ] + if unassigned_matches: + ordered_matches.extend(unassigned_matches) + + return ordered_matches + + class MatchGroup: def __init__(self, name, matches, formatted_schedule): self.name = name diff --git a/tournaments/static/tournaments/css/style.css b/tournaments/static/tournaments/css/style.css index bbb3d49..6900b2e 100644 --- a/tournaments/static/tournaments/css/style.css +++ b/tournaments/static/tournaments/css/style.css @@ -816,3 +816,11 @@ h-margin { .group-stage-link:hover { color: #f39200; /* Or whatever hover color you prefer */ } + +.empty-match-slot { + height: 100%; + min-height: 200px; /* adjust as needed */ + background-color: #f5f5f5; /* light grey background */ + border-radius: 8px; + margin: 10px; +} diff --git a/tournaments/templates/tournaments/broadcast/broadcast.html b/tournaments/templates/tournaments/broadcast/broadcast.html index 0828677..61b7dea 100644 --- a/tournaments/templates/tournaments/broadcast/broadcast.html +++ b/tournaments/templates/tournaments/broadcast/broadcast.html @@ -12,6 +12,7 @@
Automatique
+
Programmation
Matchs
Poules
Convocations
diff --git a/tournaments/templates/tournaments/broadcast/broadcast_club.html b/tournaments/templates/tournaments/broadcast/broadcast_club.html index d5e5073..6b3d617 100644 --- a/tournaments/templates/tournaments/broadcast/broadcast_club.html +++ b/tournaments/templates/tournaments/broadcast/broadcast_club.html @@ -31,6 +31,7 @@
Automatic | + Programmation | Matchs | Poules | Convocations | diff --git a/tournaments/templates/tournaments/broadcast/broadcasted_prog.html b/tournaments/templates/tournaments/broadcast/broadcasted_prog.html new file mode 100644 index 0000000..2b36c3b --- /dev/null +++ b/tournaments/templates/tournaments/broadcast/broadcasted_prog.html @@ -0,0 +1,105 @@ + +{% load static %} +{% load qr_code %} + + + + + + + + + + + Matchs + + + + + + + + + + + +
+ +
+ +
+
+ +
+ + + +
+ +
+
+ + diff --git a/tournaments/urls.py b/tournaments/urls.py index 7affe34..1862f85 100644 --- a/tournaments/urls.py +++ b/tournaments/urls.py @@ -24,8 +24,10 @@ urlpatterns = [ path('broadcast/', views.tournament_broadcast_home, name='broadcast'), path('broadcast/auto/', views.automatic_broadcast, name='automatic-broadcast'), path('matches/json/', views.tournament_matches_json, name='tournament-matches-json'), + path('prog/json/', views.tournament_prog_json, name='tournament-prog-json'), path('broadcast/json/', views.broadcast_json, name='broadcast-json'), path('broadcast/group-stages/', views.tournament_broadcasted_group_stages, name='broadcasted-group-stages'), + path('broadcast/prog/', views.tournament_broadcasted_prog, name='broadcasted-prog'), path('group-stages/', views.tournament_group_stages, name='group-stages'), path('group-stages/json/', views.tournament_live_group_stage_json, name='group-stages-json'), path('rankings/', views.tournament_rankings, name='tournament-rankings'), diff --git a/tournaments/views.py b/tournaments/views.py index 9fedd69..2d84130 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -356,6 +356,21 @@ def tournament_matches_json(request, tournament_id): data = json.dumps(live_matches, default=vars) return HttpResponse(data, content_type='application/json') +def tournament_prog_json(request, tournament_id): + tournament = get_object_or_404(Tournament, pk=tournament_id) + matches = tournament.broadcasted_prog() + + # Convert matches to JSON-serializable format, handling None/empty slots + live_matches = [] + for match in matches: + if match is None or isinstance(match, dict) and match.get('empty'): + live_matches.append({"empty": True}) + else: + live_matches.append(match.live_match()) + + data = json.dumps(live_matches, default=vars) + return HttpResponse(data, content_type='application/json') + def tournament_group_stages(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) live_group_stages = list(tournament.live_group_stages()) @@ -375,6 +390,14 @@ def tournament_broadcasted_group_stages(request, tournament_id): 'qr_code_options': qr_code_options(), }) +def tournament_broadcasted_prog(request, tournament_id): + tournament = get_object_or_404(Tournament, pk=tournament_id) + return render(request, 'tournaments/broadcast/broadcasted_prog.html', { + 'tournament': tournament, + 'qr_code_url': qr_code_url(request, tournament_id), + 'qr_code_options': qr_code_options(), + }) + def tournament_live_group_stage_json(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id)