|
|
|
|
@ -75,10 +75,10 @@ class Tournament(models.Model): |
|
|
|
|
match_groups = [] |
|
|
|
|
if group_stage_id: |
|
|
|
|
group_stage = self.groupstage_set.filter(id=group_stage_id).first() |
|
|
|
|
match_groups.append(self.group_stage_match_group(group_stage, broadcasted)) |
|
|
|
|
match_groups.append(self.group_stage_match_group(group_stage, broadcasted, hide_empty_matches=False)) |
|
|
|
|
elif round_id: |
|
|
|
|
round = self.round_set.filter(id=round_id).first() |
|
|
|
|
match_groups = self.round_match_groups(round, broadcasted) |
|
|
|
|
match_groups = self.round_match_groups(round, broadcasted, hide_empty_matches=False) |
|
|
|
|
else: |
|
|
|
|
match_groups = self.all_groups(broadcasted) |
|
|
|
|
|
|
|
|
|
@ -86,29 +86,46 @@ class Tournament(models.Model): |
|
|
|
|
|
|
|
|
|
def all_groups(self, broadcasted): |
|
|
|
|
groups = [] |
|
|
|
|
for group_stage in self.groupstage_set.all(): |
|
|
|
|
group = self.group_stage_match_group(group_stage, broadcasted) |
|
|
|
|
groups.append(group) |
|
|
|
|
for round in self.round_set.all(): |
|
|
|
|
groups.extend(self.round_match_groups(round, broadcasted)) |
|
|
|
|
groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) |
|
|
|
|
for group_stage in self.groupstage_set.all(): |
|
|
|
|
group = self.group_stage_match_group(group_stage, broadcasted, hide_empty_matches=True) |
|
|
|
|
if group: |
|
|
|
|
groups.append(group) |
|
|
|
|
return groups |
|
|
|
|
|
|
|
|
|
def group_stage_match_group(self, group_stage, broadcasted): |
|
|
|
|
return self.create_match_group(group_stage.name(), group_stage.match_set.all(), broadcasted) |
|
|
|
|
def group_stage_match_group(self, group_stage, broadcasted, hide_empty_matches): |
|
|
|
|
matches = group_stage.match_set.all() |
|
|
|
|
if hide_empty_matches: |
|
|
|
|
matches = [m for m in matches if m.should_appear()] |
|
|
|
|
|
|
|
|
|
if matches: |
|
|
|
|
return self.create_match_group(group_stage.name(), matches, broadcasted) |
|
|
|
|
else: |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
def round_match_groups(self, round, broadcasted): |
|
|
|
|
def round_match_groups(self, round, broadcasted, hide_empty_matches): |
|
|
|
|
groups = [] |
|
|
|
|
group = self.create_match_group(round.name(), round.match_set.all(), broadcasted) |
|
|
|
|
groups.append(group) |
|
|
|
|
for child in round.children.all(): |
|
|
|
|
children_groups = self.round_match_groups(child, broadcasted) |
|
|
|
|
groups.extend(children_groups) |
|
|
|
|
|
|
|
|
|
matches = round.match_set.all() |
|
|
|
|
if hide_empty_matches: |
|
|
|
|
matches = [m for m in matches if m.should_appear()] |
|
|
|
|
|
|
|
|
|
if matches: |
|
|
|
|
group = self.create_match_group(round.name(), round.match_set.all(), broadcasted) |
|
|
|
|
groups.append(group) |
|
|
|
|
|
|
|
|
|
ranking_matches = round.ranking_matches(hide_empty_matches) |
|
|
|
|
if len(ranking_matches) > 0: |
|
|
|
|
group = self.create_match_group('Matchs de classement', ranking_matches, broadcasted) |
|
|
|
|
groups.append(group) |
|
|
|
|
|
|
|
|
|
return groups |
|
|
|
|
|
|
|
|
|
def create_match_group(self, name, matches, broadcasted): |
|
|
|
|
if not broadcasted: |
|
|
|
|
matches = [m for m in matches if len(m.team_scores.all()) > 0] |
|
|
|
|
matches = list(matches) |
|
|
|
|
# if not broadcasted: |
|
|
|
|
# matches = [m for m in matches if m.should_appear()] |
|
|
|
|
matches.sort(key=lambda m: m.order) |
|
|
|
|
live_matches = [match.live_match() for match in matches] |
|
|
|
|
return MatchGroup(name, live_matches) |
|
|
|
|
|