From 00ea79f88a08fd843fc7471adcfd25446ed9a2c1 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 10 Mar 2025 10:53:46 +0100 Subject: [PATCH 1/4] Fix date formatting --- tournaments/models/tournament.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 3740561..1ae1c3f 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -170,7 +170,7 @@ class Tournament(models.Model): return self.get_federal_age_category_display() def formatted_start_date(self): - return self.start_date.strftime("%d/%m/%y") + return self.local_start_date().strftime("%d/%m/%y") def in_progress(self): return self.end_date is None From f394bb5eab251dbd3f6c3e79ffd1f538cb3642fc Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 10 Mar 2025 11:03:14 +0100 Subject: [PATCH 2/4] attempt to fix local dates --- tournaments/models/tournament.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 617926c..484b702 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() From daa3418f35c2ffd4f3ff2f9ad9f8cff789bbdb49 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 10 Mar 2025 11:08:23 +0100 Subject: [PATCH 3/4] revert test --- tournaments/models/tournament.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 484b702..617926c 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 = self.local_start_date() + timezoned_datetime = timezone.localtime(self.start_date) end = timezoned_datetime + timedelta(days=self.day_duration + 1) now = timezone.now() From 8074739d22305ba7e8bed3e703670ae325519bbe Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 10 Mar 2025 11:22:51 +0100 Subject: [PATCH 4/4] 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)