From 2a11d92de2bc2646d135b6145e3697d2e42f77fe Mon Sep 17 00:00:00 2001 From: Laurent Date: Sat, 27 Apr 2024 17:44:28 +0200 Subject: [PATCH] Dont show empty matches in broadcast + fix round identification --- tournaments/models/round.py | 6 ++++++ tournaments/models/tournament.py | 18 +++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tournaments/models/round.py b/tournaments/models/round.py index 8371d28..640f4df 100644 --- a/tournaments/models/round.py +++ b/tournaments/models/round.py @@ -60,3 +60,9 @@ class Round(models.Model): # print(f"{self.name()} > COUNT REC = {len(matches)}") return matches + + def root_round(self): + if self.parent is None: + return self + else: + return self.parent.root_round() diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 7ab9e94..cb2d180 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -177,24 +177,28 @@ class Tournament(models.Model): matches = self.group_stages_matches() else: last_started_match = self.first_unfinished_match() - current_round = last_started_match.round + current_round = last_started_match.round.root_round() previous_round = self.round_for_index(current_round.index + 1) if previous_round: - matches.extend(current_round.get_matches_recursive(False)) - matches.extend(previous_round.get_matches_recursive(False)) + matches.extend(current_round.get_matches_recursive(True)) + matches.extend(previous_round.get_matches_recursive(True)) else: - matches.extend(current_round.all_matches()) + matches.extend(current_round.all_matches(True)) group_stages = self.live_group_stages() return matches, group_stages - def all_matches(self): + def all_matches(self, hide_empty_matches): matches = [] for round in self.round_set.all(): matches.extend(round.all_matches()) for group_stage in self.groupstage_set.all(): matches.extend(group_stage.match_set.all()) + + if hide_empty_matches: + matches = [m for m in matches if m.should_appear()] + return matches def group_stage_matches(self): @@ -212,12 +216,12 @@ class Tournament(models.Model): return False def first_unfinished_match(self): - matches = [m for m in self.all_matches() if m.start_date and m.end_date is None] + matches = [m for m in self.all_matches(False) if m.start_date and m.end_date is None] matches.sort(key=lambda m: m.start_date) return matches[0] def last_started_match(self): - matches = [m for m in self.all_matches() if m.start_date] + matches = [m for m in self.all_matches(False) if m.start_date] matches.sort(key=lambda m: m.start_date, reverse=True) return matches[0]