From 08761d69021cc9c3feac217c44491adcc3905926 Mon Sep 17 00:00:00 2001 From: Raz Date: Wed, 25 Sep 2024 15:49:40 +0200 Subject: [PATCH] fix gs matches ordering --- tournaments/models/tournament.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 63e93e5..f644ebd 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -372,10 +372,13 @@ class Tournament(models.Model): groups = [] if self.display_matches(): - for round in self.round_set.filter(parent=None).all().order_by('index'): + for round in self.round_set.filter(parent=None, group_stage_loser_bracket=False).all().order_by('index'): groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) if self.display_group_stages(): + for round in self.round_set.filter(parent=None, group_stage_loser_bracket=True).all().order_by('index'): + groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) + for group_stage in self.groupstage_set.all().order_by('index'): group = self.group_stage_match_group(group_stage, broadcasted, hide_empty_matches=True) if group: @@ -390,6 +393,8 @@ class Tournament(models.Model): else: matches = [m for m in matches if m.disabled is False] + matches.sort(key=lambda m: (m.start_date is None, m.end_date is not None, m.start_date, m.index)) + if matches: return self.create_match_group(group_stage.display_name(), matches) else: @@ -405,6 +410,7 @@ class Tournament(models.Model): matches = [m for m in matches if m.disabled is False] if matches: + matches.sort(key=lambda m: m.index) group = self.create_match_group(round.name(), matches) groups.append(group) @@ -415,6 +421,7 @@ class Tournament(models.Model): ranking_matches = [m for m in ranking_matches if m.disabled is False] if len(ranking_matches) > 0: + ranking_matches.sort(key=lambda m: m.index) group = self.create_match_group('Matchs de classement', ranking_matches) groups.append(group) @@ -422,7 +429,6 @@ class Tournament(models.Model): def create_match_group(self, name, matches): matches = list(matches) - matches.sort(key=lambda m: m.index) live_matches = [match.live_match() for match in matches] return MatchGroup(name, live_matches)