From f5dcf2fbdb83e0f473f9f02899930a42881675aa Mon Sep 17 00:00:00 2001 From: Raz Date: Tue, 15 Oct 2024 20:59:08 +0200 Subject: [PATCH] fix summons --- tournaments/models/tournament.py | 40 +++++++++++++++++++++----------- tournaments/views.py | 2 +- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index d606af4..ada92c0 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -170,7 +170,7 @@ class Tournament(models.Model): return None def registration_count_display(self): - teams = self.teams() + teams = self.teams(True) if teams is not None and len(teams) > 0: return f"{len(teams)} équipes inscrites" else: @@ -180,7 +180,7 @@ class Tournament(models.Model): if self.is_canceled() is True: return "Annulé" - teams = self.teams() + teams = self.teams(True) if self.supposedly_in_progress() or self.end_date is not None: teams = [t for t in teams if t.stage != "Attente"] if teams is not None and len(teams) > 0: @@ -214,15 +214,23 @@ class Tournament(models.Model): def team_summons(self): summons = [] - for team_registration in self.teamregistration_set.all(): - if team_registration.is_valid_for_summon(): - next_match = team_registration.next_match() - if next_match and next_match.start_date is not None: - names = team_registration.team_names() - stage = next_match.summon_stage_name() - weight = team_registration.weight - summon = TeamSummon(names, next_match.start_date, weight, stage, next_match.court_name(next_match.court_index), team_registration.logo) - summons.append(summon) + if self.supposedly_in_progress() and self.end_date is None: + for team in self.teams(False): + names = team.names + stage = team.stage + weight = team.weight + summon = TeamSummon(names, team.date, weight, stage, "", team.image) + summons.append(summon) + else: + for team_registration in self.teamregistration_set.all(): + if team_registration.is_valid_for_summon(): + next_match = team_registration.next_match() + if next_match and next_match.start_date is not None: + names = team_registration.team_names() + stage = next_match.summon_stage_name() + weight = team_registration.weight + summon = TeamSummon(names, next_match.start_date, weight, stage, next_match.court_name(next_match.court_index), team_registration.logo) + summons.append(summon) summons.sort(key=lambda s: s.date) return summons @@ -248,7 +256,7 @@ class Tournament(models.Model): rankings.sort(key=lambda r: r.ranking) return rankings - def teams(self): + def teams(self, includeWaitingList): print("Starting teams method") bracket_teams = [] group_stage_teams = [] @@ -368,8 +376,12 @@ class Tournament(models.Model): for team in waiting_teams: team.set_stage("Attente") - final_teams = bracket_teams + group_stage_teams + waiting_teams - print(f"Final teams: {len(final_teams)}") + if includeWaitingList is True: + final_teams = bracket_teams + group_stage_teams + waiting_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)}") return final_teams diff --git a/tournaments/views.py b/tournaments/views.py index d6bb001..eba7ca5 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -166,7 +166,7 @@ def tournament(request, tournament_id): def tournament_teams(request, tournament_id): tournament = get_object_or_404(Tournament, pk=tournament_id) - teams = tournament.teams() + teams = tournament.teams(True) return render(request, 'tournaments/teams.html', { 'tournament': tournament,