Fixes broadcast state

clubs
Laurent 2 years ago
parent 313cf67943
commit 125b5e1517
  1. 16
      tournaments/models/tournament.py

@ -171,19 +171,20 @@ class Tournament(models.Model):
matches = [] matches = []
group_stages = [] group_stages = []
if self.group_stages_running():
matches = self.group_stages_matches()
else:
last_started_match = self.first_unfinished_match() last_started_match = self.first_unfinished_match()
current_round = last_started_match.round current_round = last_started_match.round
if current_round:
previous_round = self.round_for_index(current_round.index + 1) previous_round = self.round_for_index(current_round.index + 1)
if previous_round: if previous_round:
matches.extend(current_round.get_matches_recursive(False)) matches.extend(current_round.get_matches_recursive(False))
matches.extend(previous_round.get_matches_recursive(False)) matches.extend(previous_round.get_matches_recursive(False))
else: else:
matches.extend(current_round.all_matches()) matches.extend(current_round.all_matches())
group_stages = self.live_group_stages() group_stages = self.live_group_stages()
else:
matches = self.group_stages_matches()
return matches, group_stages return matches, group_stages
@ -195,6 +196,13 @@ class Tournament(models.Model):
matches.extend(group_stage.match_set.all()) matches.extend(group_stage.match_set.all())
return matches return matches
def group_stages_running(self):
if len(self.groupstage_set.all()) > 0:
running_group_stage_matches = Match.objects.filter(group_stage__is_null=False, end_date=None)
return len(running_group_stage_matches) > 0
else:
return False
def first_unfinished_match(self): def first_unfinished_match(self):
matches = [m for m in self.all_matches() if m.start_date and m.end_date is None] 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) matches.sort(key=lambda m: m.start_date)

Loading…
Cancel
Save