From 6240c4d678e840b1140796bba2276000386c7a84 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 25 Oct 2024 09:27:48 +0200 Subject: [PATCH] Fix tournament mistakenly appearing in progress --- tournaments/models/tournament.py | 62 ++++++++++++++++++++------------ tournaments/views.py | 11 ++---- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index c2fa385..1acea4e 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -232,6 +232,7 @@ class Tournament(models.Model): def team_summons(self): summons = [] + print('>>> team_summons') if self.supposedly_in_progress() and self.end_date is None: for team in self.teams(False): names = team.names @@ -275,7 +276,7 @@ class Tournament(models.Model): return rankings def teams(self, includeWaitingList): - print("Starting teams method") + # print("Starting teams method") bracket_teams = [] group_stage_teams = [] waiting_teams = [] @@ -284,10 +285,10 @@ class Tournament(models.Model): wildcard_group_stage = [] complete_teams = [] closed_registration_date = self.closed_registration_date - print(f"Closed registration date: {closed_registration_date}") + # print(f"Closed registration date: {closed_registration_date}") for team_registration in self.teamregistration_set.all(): - print(f"Processing team registration: {team_registration}") + # print(f"Processing team registration: {team_registration}") is_valid = False if closed_registration_date is not None and team_registration.registration_date is not None and team_registration.registration_date <= closed_registration_date: is_valid = True @@ -295,7 +296,7 @@ class Tournament(models.Model): is_valid = True if team_registration.registration_date is None: is_valid = True - print(f"Is valid: {is_valid}") + # print(f"Is valid: {is_valid}") if team_registration.walk_out is False: names = team_registration.team_names() @@ -303,14 +304,14 @@ class Tournament(models.Model): initial_weight = team_registration.initial_weight() date = team_registration.call_date team = TeamList(names, weight, date, initial_weight, team_registration.wild_card_bracket, team_registration.wild_card_group_stage, team_registration.logo) - print(f"Created team: {team}") + # print(f"Created team: {team}") if team_registration.group_stage_position is not None: team.set_stage("Poule") elif team_registration.bracket_position is not None: team.set_stage("Tableau") else: team.set_stage("Attente") - print(f"Team stage: {team.stage}") + # print(f"Team stage: {team.stage}") teams.append(team) if team_registration.wild_card_bracket: @@ -322,11 +323,11 @@ class Tournament(models.Model): else: waiting_teams.append(team) - print(f"Total teams: {len(teams)}") - print(f"Wildcard bracket: {len(wildcard_bracket)}") - print(f"Wildcard group stage: {len(wildcard_group_stage)}") - print(f"Complete teams: {len(complete_teams)}") - print(f"Waiting teams: {len(waiting_teams)}") + # print(f"Total teams: {len(teams)}") + # print(f"Wildcard bracket: {len(wildcard_bracket)}") + # print(f"Wildcard group stage: {len(wildcard_group_stage)}") + # print(f"Complete teams: {len(complete_teams)}") + # print(f"Waiting teams: {len(waiting_teams)}") if len(teams) < self.team_count: teams.sort(key=lambda s: (s.initial_weight, s.date)) @@ -339,8 +340,8 @@ class Tournament(models.Model): group_stage_members_count = 0 if seeds_count < 0: seeds_count = 0 - print(f"Seeds count: {seeds_count}") - print(f"Group stage members count: {group_stage_members_count}") + # print(f"Seeds count: {seeds_count}") + # print(f"Group stage members count: {group_stage_members_count}") if self.team_sorting == TeamSortingType.INSCRIPTION_DATE: complete_teams.sort(key=lambda s: (s.date is None, s.date or datetime.min, s.initial_weight)) @@ -349,25 +350,25 @@ class Tournament(models.Model): selected_teams = complete_teams[:self.team_count] selected_teams.sort(key=lambda s: s.initial_weight) - print(f"Selected teams: {len(selected_teams)}") + # print(f"Selected teams: {len(selected_teams)}") if seeds_count > 0: bracket_teams = selected_teams[:seeds_count] + wildcard_bracket else: bracket_teams = [] - print(f"Bracket teams: {len(bracket_teams)}") + # print(f"Bracket teams: {len(bracket_teams)}") if group_stage_members_count: group_stage_end = seeds_count + group_stage_members_count group_stage_teams = selected_teams[seeds_count:group_stage_end] + wildcard_group_stage else: group_stage_teams = [] - print(f"Group stage teams: {len(group_stage_teams)}") + # print(f"Group stage teams: {len(group_stage_teams)}") waiting_list_count = len(teams) - self.team_count if waiting_list_count < 0: waiting_list_count = 0 - print(f"Waiting list count: {waiting_list_count}") + # print(f"Waiting list count: {waiting_list_count}") if waiting_list_count > 0 or len(waiting_teams) > 0: if waiting_list_count > 0: @@ -378,7 +379,7 @@ class Tournament(models.Model): waiting_teams.sort(key=lambda s: (s.initial_weight, s.date)) else: waiting_teams = [] - print(f"Final waiting teams: {len(waiting_teams)}") + # print(f"Final waiting teams: {len(waiting_teams)}") bracket_teams.sort(key=lambda s: s.weight) group_stage_teams.sort(key=lambda s: s.weight) @@ -396,10 +397,10 @@ class Tournament(models.Model): if includeWaitingList is True: final_teams = bracket_teams + group_stage_teams + waiting_teams - print(f"Final teams with waiting list: {len(final_teams)}") + # print(f"Final teams with waiting list: {len(final_teams)}") else: final_teams = bracket_teams + group_stage_teams - print(f"Final teams without waiting list: {len(final_teams)}") + # print(f"Final teams without waiting list: {len(final_teams)}") return final_teams @@ -807,8 +808,23 @@ class Tournament(models.Model): return date.replace(hour=8, minute=0, second=0, microsecond=0, tzinfo=date.tzinfo) def supposedly_in_progress(self): - end = self.start_date + timedelta(days=self.day_duration + 1) - return self.start_date.replace(hour=0, minute=0) <= timezone.now() <= end + # 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) + end = timezoned_datetime + timedelta(days=self.day_duration + 1) + now = timezone.now() + + start = timezoned_datetime.replace(hour=0, minute=0) + + print(f"timezoned_datetime: {timezoned_datetime}") + print(f"tournament end date: {end}") + print(f"current time: {now}") + print(f"tournament start: {start}") + print(f"start <= now <= end: {start <= now <= end}") + + return start <= now <= end + def display_points_earned(self): return self.federal_level_category != FederalLevelCategory.UNLISTED and self.hide_points_earned is False @@ -858,7 +874,7 @@ class TeamSummon: if self.date: return formats.date_format(self.date, format='l H:i') else: - return None + return '' def to_dict(self): return { diff --git a/tournaments/views.py b/tournaments/views.py index 367b32c..e30e420 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -79,8 +79,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 = date.today() + timedelta(days=1) - tournaments = tournaments_query(Q(end_date__isnull=True, start_date__gt=tomorrow), club_id, True) + 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()] def tournament_info(request, tournament_id): @@ -147,13 +147,8 @@ def tournament(request, tournament_id): rounds = list(tournament.round_set.filter(group_stage_loser_bracket=True)) rounds.extend(bracket_rounds) - #group_stages = tournament.groupstage_set.order_by('index') group_stages = sorted(tournament.get_computed_group_stage(), key=lambda s: (s.step, s.index)) - #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', { 'tournament': tournament, @@ -430,7 +425,7 @@ def simple_form_view(request): return HttpResponse(f"Hello, {name}!") # Simple response with name else: form = SimpleForm() - print(request.method) + # print(request.method) # If this is a GET request, we display an empty form return render(request, 'tournaments/admin/mail_test.html', {'form': form})