Fixes match order and display

clubs
Laurent 2 years ago
parent ea7be53272
commit 156044e41a
  1. 3
      tournaments/models/match.py
  2. 15
      tournaments/models/round.py
  3. 43
      tournaments/models/tournament.py
  4. 2
      tournaments/views.py

@ -90,6 +90,9 @@ class Match(models.Model):
else:
return False
def should_appear(self):
return self.start_date and len(self.team_scores.all()) > 0
def formatted_duration(self):
_seconds = self.current_duration()

@ -27,8 +27,7 @@ class Round(models.Model):
def name(self):
if self.loser:
parent = self.loser.name()
return f"Matchs de classement [{parent}]"
return "Matchs de classement"
else:
if self.index == 0:
return "Finale"
@ -39,3 +38,15 @@ class Round(models.Model):
else:
squared = 2 ** self.index
return f"{squared}ème"
def ranking_matches(self, hide_empty_matches):
matches = []
for child in self.children.all():
child_matches = child.match_set.all()
if hide_empty_matches:
child_matches = [m for m in matches if m.should_appear()]
matches.extend(child_matches)
matches.extend(child.ranking_matches(hide_empty_matches))
return matches

@ -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 round in self.round_set.all():
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)
group = self.group_stage_match_group(group_stage, broadcasted, hide_empty_matches=True)
if group:
groups.append(group)
for round in self.round_set.all():
groups.extend(self.round_match_groups(round, broadcasted))
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 = []
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)
for child in round.children.all():
children_groups = self.round_match_groups(child, broadcasted)
groups.extend(children_groups)
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)

@ -78,8 +78,6 @@ def tournament(request, tournament_id):
rounds = tournament.round_set.filter(loser=None).order_by('-index')
group_stages = tournament.groupstage_set.order_by('index')
print(f"GROUPS = {len(match_groups)}")
return render(request, 'tournaments/matches.html', {
'tournament': tournament,
'rounds': rounds,

Loading…
Cancel
Save