From 668ebddc4bc775f3e400d3392e792216f3b7db6e Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 6 Dec 2024 15:58:51 +0100 Subject: [PATCH] change round to show --- tournaments/models/tournament.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 53b2503..af5d720 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -685,19 +685,37 @@ class Tournament(models.Model): print(f'round_to_show > current_round: {current_round.name()}') if current_round: return current_round - main_rounds = list(self.round_set.filter(parent=None).all()) - main_rounds.sort(key=lambda r: r.index) - if main_rounds: - print(f'round_to_show > main_rounds: {main_rounds[0].name()}') - return main_rounds[0] + + # all started matches have ended, possibly + last_finished_match = self.last_finished_match() + round_index = last_finished_match.round.index + if round_index == 0: + return last_finished_match.round else: - return None + round = self.round_set.filter(parent=None,index=round_index-1).first() + if round: + return round + else: + return None + + # main_rounds = list(self.round_set.filter(parent=None).all()) + # main_rounds.sort(key=lambda r: r.index) + # if main_rounds: + # print(f'round_to_show > main_rounds: {main_rounds[0].name()}') + # return main_rounds[0] + # else: + # return None def last_started_match(self): 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] if matches else None + def last_finished_match(self): + matches = [m for m in self.all_matches(False) if m.end_date] + matches.sort(key=lambda m: m.end_date, reverse=True) + return matches[0] if matches else None + def round_for_index(self, index): return self.round_set.filter(index=index, parent=None).first()