From 8074739d22305ba7e8bed3e703670ae325519bbe Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 10 Mar 2025 11:22:51 +0100 Subject: [PATCH] fix live/future display by local dates --- tournaments/models/tournament.py | 11 ++++++++++- tournaments/views.py | 5 ++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 617926c..5c21961 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -932,7 +932,7 @@ class Tournament(models.Model): # end = self.start_date + timedelta(days=self.day_duration + 1) # return self.start_date.replace(hour=0, minute=0) <= timezone.now() <= end - timezoned_datetime = timezone.localtime(self.start_date) + timezoned_datetime = self.local_start_date() end = timezoned_datetime + timedelta(days=self.day_duration + 1) now = timezone.now() @@ -946,6 +946,15 @@ class Tournament(models.Model): return start <= now <= end + def starts_in_the_future(self): + # tomorrow = datetime.now().date() + timedelta(days=1) + + timezoned_datetime = self.local_start_date() + start = timezoned_datetime.replace(hour=0, minute=0) + now = timezone.now() + + return start >= now + def should_be_over(self): if self.end_date is not None: return True diff --git a/tournaments/views.py b/tournaments/views.py index 7f9400e..2a82a98 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -150,9 +150,8 @@ def live_tournaments(club_id): return [t for t in tournaments if t.display_tournament() and t.supposedly_in_progress()] def future_tournaments(club_id): - tomorrow = datetime.now().date() + timedelta(days=1) - tournaments = tournaments_query(Q(end_date__isnull=True, start_date__gte=tomorrow), club_id, True) - return [t for t in tournaments if t.display_tournament()] + tournaments = tournaments_query(Q(end_date__isnull=True), club_id, True) + return [t for t in tournaments if t.display_tournament() and t.starts_in_the_future()] def tournament_info(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id)