Dont show empty matches in broadcast + fix round identification

clubs
Laurent 2 years ago
parent 2798924916
commit 2a11d92de2
  1. 6
      tournaments/models/round.py
  2. 18
      tournaments/models/tournament.py

@ -60,3 +60,9 @@ class Round(models.Model):
# print(f"{self.name()} > COUNT REC = {len(matches)}") # print(f"{self.name()} > COUNT REC = {len(matches)}")
return matches return matches
def root_round(self):
if self.parent is None:
return self
else:
return self.parent.root_round()

@ -177,24 +177,28 @@ class Tournament(models.Model):
matches = self.group_stages_matches() matches = self.group_stages_matches()
else: 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.root_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(True))
matches.extend(previous_round.get_matches_recursive(False)) matches.extend(previous_round.get_matches_recursive(True))
else: else:
matches.extend(current_round.all_matches()) matches.extend(current_round.all_matches(True))
group_stages = self.live_group_stages() group_stages = self.live_group_stages()
return matches, group_stages return matches, group_stages
def all_matches(self): def all_matches(self, hide_empty_matches):
matches = [] matches = []
for round in self.round_set.all(): for round in self.round_set.all():
matches.extend(round.all_matches()) matches.extend(round.all_matches())
for group_stage in self.groupstage_set.all(): for group_stage in self.groupstage_set.all():
matches.extend(group_stage.match_set.all()) matches.extend(group_stage.match_set.all())
if hide_empty_matches:
matches = [m for m in matches if m.should_appear()]
return matches return matches
def group_stage_matches(self): def group_stage_matches(self):
@ -212,12 +216,12 @@ class Tournament(models.Model):
return False 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(False) 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)
return matches[0] return matches[0]
def last_started_match(self): def last_started_match(self):
matches = [m for m in self.all_matches() if m.start_date] matches = [m for m in self.all_matches(False) if m.start_date]
matches.sort(key=lambda m: m.start_date, reverse=True) matches.sort(key=lambda m: m.start_date, reverse=True)
return matches[0] return matches[0]

Loading…
Cancel
Save