diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 392a47b..bd172d8 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -176,8 +176,8 @@ class Tournament(models.Model): group_stages = self.live_group_stages() matches = self.group_stages_matches() else: - last_started_match = self.first_unfinished_match() - current_round = last_started_match.round.root_round() + # last_started_match = self.first_unfinished_match() + current_round = self.round_to_show() previous_round = self.round_for_index(current_round.index + 1) if previous_round: @@ -218,7 +218,23 @@ class Tournament(models.Model): def first_unfinished_match(self): 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] + if matches: + return matches[0] + else: + return None + + def round_to_show(self): + last_started_match = self.first_unfinished_match() + if last_started_match: + current_round = last_started_match.round.root_round() + 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: + 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]