From 4cf08b6509b0dc8a0ac3e33c2627d3c4d473c6a6 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 13 Mar 2024 20:43:27 +0100 Subject: [PATCH] fixes --- tournaments/models/group_stage.py | 22 ++++++++++++------- tournaments/models/team_registration.py | 2 +- .../tournaments/broadcasted_group_stages.html | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tournaments/models/group_stage.py b/tournaments/models/group_stage.py index cf9b36a..815187a 100644 --- a/tournaments/models/group_stage.py +++ b/tournaments/models/group_stage.py @@ -28,6 +28,16 @@ class GroupStage(models.Model): def live_group_stages(self): lgs = LiveGroupStage(self.name()) gs_teams = {} + + # init all teams + for team_registration in self.teamregistration_set.all(): + if team_registration in gs_teams: + team = gs_teams[team_registration] + else: + team = GroupStageTeam(team_registration) + gs_teams[team_registration] = team + + # compute matches for match in self.match_set.all(): lgs.add_match(match) team_scores = match.team_scores.all() @@ -37,14 +47,10 @@ class GroupStage(models.Model): team_registration = team_score.team_registration if team_registration in gs_teams: team = gs_teams[team_registration] - else: - team = GroupStageTeam(team_registration) - gs_teams[team_registration] = team - - if match.winning_team_id == team_registration.id: - team.wins += 1 - else: - team.losses += 1 + if match.winning_team_id == team_registration.id: + team.wins += 1 + else: + team.losses += 1 ts1 = team_scores[0] ts2 = team_scores[1] diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index fb87fc6..7d964e1 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -40,7 +40,7 @@ class TeamRegistration(models.Model): matches = [m for m in all_matches if m.end_date is None] if matches: return matches[0] - else: + elif all_matches: return all_matches[0] def next_stage(self): diff --git a/tournaments/templates/tournaments/broadcasted_group_stages.html b/tournaments/templates/tournaments/broadcasted_group_stages.html index 8ff5232..b6b0e55 100644 --- a/tournaments/templates/tournaments/broadcasted_group_stages.html +++ b/tournaments/templates/tournaments/broadcasted_group_stages.html @@ -71,7 +71,7 @@
- +
@@ -103,7 +103,7 @@
-
+