From 98acbc77e04012bc5546ef2ddfd4867b063269da Mon Sep 17 00:00:00 2001 From: Raz Date: Thu, 3 Oct 2024 15:54:39 +0200 Subject: [PATCH] add club auto broadcast --- tournaments/models/tournament.py | 10 +- .../broadcast/broadcasted_auto_event.html | 224 ++++++++++++++++++ tournaments/urls.py | 2 + tournaments/views.py | 42 +++- 4 files changed, 273 insertions(+), 5 deletions(-) create mode 100644 tournaments/templates/tournaments/broadcast/broadcasted_auto_event.html diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 1977d31..e065f56 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -451,6 +451,8 @@ class Tournament(models.Model): 'matches': [], 'group_stages': group_stages_dicts, 'summons': team_summons_dicts, + 'event_title' : self.broadcast_event_display_name(), + 'tournament_title' : self.broadcast_display_name(), 'rankings' : [] } else: @@ -459,6 +461,8 @@ class Tournament(models.Model): 'matches': live_matches_dicts, 'group_stages': [], 'summons': team_summons_dicts, + 'event_title' : self.broadcast_event_display_name(), + 'tournament_title' : self.broadcast_display_name(), 'rankings' : [] } elif self.end_date is not None: @@ -468,6 +472,8 @@ class Tournament(models.Model): 'matches': live_matches_dicts, 'group_stages': [], 'summons': [], + 'event_title' : self.broadcast_event_display_name(), + 'tournament_title' : self.broadcast_display_name(), 'rankings' : team_rankings_dicts } else: # we want to display the broadcasted content @@ -476,7 +482,9 @@ class Tournament(models.Model): 'matches': live_matches_dicts, 'group_stages': group_stages_dicts, 'summons': [], - 'rankings' : [] + 'rankings' : [], + 'event_title' : self.broadcast_event_display_name(), + 'tournament_title' : self.broadcast_display_name(), } def broadcasted_matches_and_group_stages(self): diff --git a/tournaments/templates/tournaments/broadcast/broadcasted_auto_event.html b/tournaments/templates/tournaments/broadcast/broadcasted_auto_event.html new file mode 100644 index 0000000..7ab24a0 --- /dev/null +++ b/tournaments/templates/tournaments/broadcast/broadcasted_auto_event.html @@ -0,0 +1,224 @@ + + + {% load static %} + {% load qr_code %} + + + {% include 'tournaments/broadcast/base_head.html' %} + + + + Broadcast + + + + + + + + +
+
+ +
+ + +
+
+
+ + + + + + + + +
+ +
+
+ +
+ + diff --git a/tournaments/urls.py b/tournaments/urls.py index 93c99af..e4b316b 100644 --- a/tournaments/urls.py +++ b/tournaments/urls.py @@ -8,6 +8,7 @@ urlpatterns = [ path("clubs/", views.clubs, name="clubs"), path("clubs//", views.club, name="club"), path("c/", views.club_broadcast, name="club-broadcast"), + path("c//go", views.club_broadcast_auto, name="club-broadcast-auto"), path("tournament//", include([ path('', views.tournament, name='tournament'), @@ -29,6 +30,7 @@ urlpatterns = [ path('broadcast/rankings/', views.tournament_broadcast_rankings, name='broadcasted-rankings'), ]) ), + path("event//broadcast/auto/", views.automatic_broadcast_event, name='automatic-broadcast-event'), path('players/', views.players, name='players'), path('activate///', views.activate, name='activate'), path('download/', views.download, name='download'), diff --git a/tournaments/views.py b/tournaments/views.py index 8fdb230..382c01d 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -30,7 +30,8 @@ import os from .forms import SimpleForm from django.core.mail import EmailMessage - +from datetime import timedelta +from django.utils import timezone def index(request): @@ -147,9 +148,9 @@ def tournament(request, tournament_id): group_stages = tournament.groupstage_set.order_by('index') - print(len(match_groups)) - print(len(rounds)) - print(len(group_stages)) + #print(len(match_groups)) + #print(len(rounds)) + #print(len(group_stages)) if tournament.display_matches() or tournament.display_group_stages(): return render(request, 'tournaments/matches.html', { @@ -211,6 +212,14 @@ def automatic_broadcast(request, tournament_id): 'qr_code_options': qr_code_options(), }) +def automatic_broadcast_event(request, event_id): + event = get_object_or_404(Event, pk=event_id) + tournaments = Tournament.objects.filter(event=event) + tournament_ids = [str(tournament.id) for tournament in tournaments] + return render(request, 'tournaments/broadcast/broadcasted_auto_event.html', { + 'tournament_ids': tournament_ids, + }) + def qr_code_url(request, tournament_id): qr_code_url = reverse('tournament', args=[tournament_id]) return request.build_absolute_uri(qr_code_url) @@ -314,6 +323,31 @@ def club_broadcast(request, broadcast_code): 'tournaments': tournaments, }) +def club_broadcast_auto(request, broadcast_code): + club = get_object_or_404(Club, broadcast_code=broadcast_code) + q_not_deleted = Q(is_deleted=False, event__club=club) + now = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + + recent_time_window = now - timedelta(hours=4) + + tournaments = Tournament.objects.filter( + q_not_deleted, + ( + Q(end_date__isnull=True) | # Include ongoing tournaments + Q(start_date__lt=now + timedelta(days=3)) # Include tournaments starting in the next 3 days + ), + Q(is_private=False) # Exclude private tournaments + ).filter( + Q(end_date__gte=recent_time_window) | # Include tournaments that just finished in the last 4 hours + Q(end_date__isnull=True) # Ensure ongoing tournaments are included + ) + + tournament_ids = [str(tournament.id) for tournament in tournaments] + #print(tournament_ids) + return render(request, 'tournaments/broadcast/broadcasted_auto_event.html', { + 'tournament_ids': tournament_ids, + }) + def download(request): return render(request, 'tournaments/download.html')