performance #3

apikeys
Laurent 3 months ago
parent 1e958cca57
commit c5e910a208
  1. 7
      tournaments/models/match.py
  2. 8
      tournaments/models/team_registration.py
  3. 2
      tournaments/models/tournament.py

@ -194,13 +194,14 @@ class Match(TournamentSubModel):
teams = []
# Check if team scores exist
team_scores_count = self.team_scores.count()
team_scores = list(self.team_scores.all())
previous_top_match = self.precedent_match(True)
previous_bottom_match = self.precedent_match(False)
loser_top_match = self.loser_precedent_match(True)
loser_bottom_match = self.loser_precedent_match(False)
if len(team_scores) == 0 or hide_names is True:
if team_scores_count == 0 or hide_names is True:
if (self.round and self.round.parent is None and self.round.tournament.rounds.filter(parent__isnull=True, group_stage_loser_bracket=False).count() - 1 == self.round.index):
names = ["Qualifié"]
@ -248,7 +249,7 @@ class Match(TournamentSubModel):
names = [f"Gagnant {previous_bottom_match.computed_name()}"]
team = self.default_live_team(names)
teams.append(team)
elif len(team_scores) == 1:
elif team_scores_count == 1:
# Only one team score, handle missing one
existing_team = team_scores[0].live_team(self, short_names=short_names)
if (self.group_stage):
@ -288,7 +289,7 @@ class Match(TournamentSubModel):
teams.append(team)
teams.append(existing_team)
elif len(team_scores) == 2:
elif team_scores_count:
# Both team scores present
teams.extend([team_score.live_team(self, short_names=short_names) for team_score in team_scores])

@ -74,17 +74,19 @@ class TeamRegistration(TournamentSubModel):
if self.name:
return [self.name] #add an empty line if it's a team name
else:
players = list(self.players_sorted_by_rank)
if len(players) == 0:
player_count = self.player_registrations.count()
if player_count == 0:
if self.wild_card_bracket:
return ['Place réservée wildcard']
elif self.wild_card_group_stage:
return ['Place réservée wildcard']
else:
return ['Place réservée']
elif len(players) == 1:
elif player_count == 1:
players = list(self.players_sorted_by_rank)
return [players[0].shortened_name(forced=forced)]
else:
players = list(self.players_sorted_by_rank)
return [pr.shortened_name(forced=forced) for pr in players]
@property

@ -506,7 +506,7 @@ class Tournament(BaseModel):
group_stage = self.group_stages.filter(id=group_stage_id).first()
match_groups.append(self.group_stage_match_group(group_stage, broadcasted, hide_empty_matches=False))
elif round_id:
round = self.rounds.filter(id=round_id).first().prefetch_related('matches')
round = self.rounds.filter(id=round_id).first()
if round and display_brackets is True:
match_groups = self.round_match_groups(round, broadcasted, hide_empty_matches=False)
else:

Loading…
Cancel
Save