diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 90a29a9..ee799c8 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -109,7 +109,7 @@ class Tournament(models.Model): def round_match_groups(self, round, broadcasted, hide_empty_matches): groups = [] - matches = round.match_set.all() + matches = round.match_set.order_by('index').all() if hide_empty_matches: matches = [m for m in matches if m.should_appear()] @@ -128,7 +128,7 @@ class Tournament(models.Model): matches = list(matches) # if not broadcasted: # matches = [m for m in matches if m.should_appear()] - matches.sort(key=lambda m: m.order) + matches.sort(key=lambda m: m.index) live_matches = [match.live_match() for match in matches] return MatchGroup(name, live_matches) @@ -175,7 +175,7 @@ class Tournament(models.Model): matches = [] group_stages = [] - last_started_match = self.last_started_match() + last_started_match = self.first_unfinished_match() current_round = last_started_match.round if current_round: @@ -199,6 +199,11 @@ class Tournament(models.Model): matches.extend(group_stage.match_set.all()) return matches + def first_unfinished_match(self): + matches = [m for m in self.all_matches() 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.sort(key=lambda m: m.start_date, reverse=True) @@ -235,8 +240,11 @@ class TeamSummon: self.image = image def formatted_date(self): - timezoned_datetime = timezone.localtime(self.date) - return formats.date_format(timezoned_datetime, format='H:i') + if self.date: + timezoned_datetime = timezone.localtime(self.date) + return formats.date_format(timezoned_datetime, format='H:i') + else: + return None def to_dict(self): return {