diff --git a/tournaments/models/group_stage.py b/tournaments/models/group_stage.py index 94d83eb..85415a9 100644 --- a/tournaments/models/group_stage.py +++ b/tournaments/models/group_stage.py @@ -102,6 +102,12 @@ class GroupStage(models.Model): else: return False + def has_at_least_one_started_match(self): + for match in self.match_set.all(): + if match.start_date: + return True + return False + class LiveGroupStage: def __init__(self, title): self.title = title diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 45711d7..3b12130 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -358,7 +358,7 @@ class Tournament(models.Model): matches = [m for m in matches if m.disabled is False] if matches: - return self.create_match_group(group_stage.display_name(), matches, broadcasted) + return self.create_match_group(group_stage.display_name(), matches) else: return None @@ -372,7 +372,7 @@ class Tournament(models.Model): matches = [m for m in matches if m.disabled is False] if matches: - group = self.create_match_group(round.name(), matches, broadcasted) + group = self.create_match_group(round.name(), matches) groups.append(group) ranking_matches = round.ranking_matches(hide_empty_matches) @@ -382,12 +382,12 @@ class Tournament(models.Model): ranking_matches = [m for m in ranking_matches if m.disabled is False] if len(ranking_matches) > 0: - group = self.create_match_group('Matchs de classement', ranking_matches, broadcasted) + group = self.create_match_group('Matchs de classement', ranking_matches) groups.append(group) return groups - def create_match_group(self, name, matches, broadcasted): + 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] @@ -436,7 +436,7 @@ class Tournament(models.Model): group_stages = self.live_group_stages() matches = self.broadcasted_group_stages_matches() first_round = self.first_round() - if first_round: + if first_round and self.has_all_group_stages_started(): matches.extend(first_round.get_matches_recursive(True)) else: current_round = self.round_to_show() @@ -596,16 +596,6 @@ class Tournament(models.Model): else: return timezone.now() >= first_group_stage_start_date - # group_stage_start_date = self.getEightAm(first_group_stage_start_date) - - # if group_stage_start_date < self.start_date: - # group_stage_start_date = self.start_date - - # if datetime.now().date() >= group_stage_start_date.date(): - # return True - - # return False - def group_stage_start_date(self): group_stages = [gs for gs in self.groupstage_set.all() if gs.start_date is not None] if len(group_stages) == 0: @@ -673,6 +663,12 @@ class Tournament(models.Model): else: return False + def has_all_group_stages_started(self): + for group_stage in self.groupstage_set.all(): + if group_stage.has_at_least_one_started_match() == False + return False + return True + class MatchGroup: def __init__(self, name, matches): self.name = name