From 526aa6f665b472c65c7420430f5b243102801288 Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 30 May 2024 11:51:07 +0200 Subject: [PATCH] Fixes issue with in progress tournaments --- tournaments/models/tournament.py | 2 +- tournaments/views.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 16475b1..408b06c 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -535,7 +535,7 @@ class Tournament(models.Model): def supposedly_in_progress(self): end = self.start_date + timedelta(days=self.day_duration) - return timezone.now() > self.start_date.replace(hour=0, minute=0) and timezone.now() < end + return self.start_date.replace(hour=0, minute=0) <= timezone.now() <= end class MatchGroup: def __init__(self, name, matches): diff --git a/tournaments/views.py b/tournaments/views.py index 09590de..5027d26 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -33,15 +33,14 @@ from qr_code.qrcode.utils import QRCodeOptions def index(request): - today = date.today() - tomorrow = today + timedelta(days=1) + tomorrow = date.today() + timedelta(days=1) club_id = request.GET.get('club') - q_is_private = Q(is_private=False) + q_not_private = Q(is_private=False) - q_after_tomorrow = [q_is_private, Q(end_date__isnull=True, start_date__gt=tomorrow)] - q_after_today = [q_is_private, Q(end_date__isnull=True, start_date__gt=today)] - q_ended = [q_is_private, Q(end_date__isnull=False)] + q_after_tomorrow = [q_not_private, Q(end_date__isnull=True, start_date__gt=tomorrow)] + q_unfinished = [q_not_private, Q(end_date__isnull=True)] + q_ended = [q_not_private, Q(end_date__isnull=False)] club = None if club_id: @@ -49,14 +48,14 @@ def index(request): q_club = Q(event__club=club) q_after_tomorrow.append(q_club) - q_after_today.append(q_club) + q_unfinished.append(q_club) q_ended.append(q_club) after_tomorrow_tournaments = Tournament.objects.filter(*q_after_tomorrow).order_by('start_date') - after_today_tournaments = Tournament.objects.filter(*q_after_today).order_by('start_date') + unfinished_tournaments = Tournament.objects.filter(*q_unfinished).order_by('start_date') live_tournaments = [] - for tournament in after_today_tournaments: + for tournament in unfinished_tournaments: if tournament.supposedly_in_progress(): live_tournaments.append(tournament)