From a000dd4d6b5e5598bdb5570d3b99694c15b6f739 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 24 Apr 2024 13:06:12 +0200 Subject: [PATCH] Minor improvements --- tournaments/admin.py | 2 +- tournaments/models/group_stage.py | 14 ++- tournaments/models/match.py | 7 +- tournaments/models/team_registration.py | 4 +- .../tournaments/group_stage_cell.html | 99 ++++++++----------- .../templates/tournaments/match_cell.html | 6 +- .../templates/tournaments/tournaments.html | 19 +++- 7 files changed, 79 insertions(+), 72 deletions(-) diff --git a/tournaments/admin.py b/tournaments/admin.py index 89ca969..703fda3 100644 --- a/tournaments/admin.py +++ b/tournaments/admin.py @@ -24,7 +24,7 @@ class CustomUserAdmin(UserAdmin): ] class TeamRegistrationAdmin(admin.ModelAdmin): - list_display = ['player_names', 'name', 'tournament'] + list_display = ['player_names', 'group_stage_position', 'name', 'tournament'] class TournamentAdmin(admin.ModelAdmin): list_display = ['name', 'event', 'is_private', 'start_date'] diff --git a/tournaments/models/group_stage.py b/tournaments/models/group_stage.py index 1b9af33..2411bee 100644 --- a/tournaments/models/group_stage.py +++ b/tournaments/models/group_stage.py @@ -79,10 +79,10 @@ class GroupStage(models.Model): team1.diff += total1 - total2 team2.diff += total2 - total1 - if len(self.match_set.all()) == 0: - teams = sorted(gs_teams.values(), key=lambda team: team.position) - else: + if len(self.match_set.filter(end_date__isnull=False).all()) > 0: teams = sorted(gs_teams.values(), key=lambda team: -(team.wins * 100 + team.diff)) + else: + teams = sorted(gs_teams.values(), key=lambda team: team.position) for team in teams: lgs.add_team(team) @@ -131,10 +131,14 @@ class GroupStageTeam: self.wins = 0 self.losses = 0 self.diff = 0 + self.weight = team_registration.weight() def wins_losses(self): return f"{self.wins}/{self.losses}" + def match_count(self): + return self.wins + self.losses + def formatted_diff(self): if self.diff >= 0: return f"+{self.diff}" @@ -145,5 +149,7 @@ class GroupStageTeam: return { "names": self.names, "win_loss": self.wins_losses(), - "diff": self.formatted_diff() + "diff": self.formatted_diff(), + "weight": self.weight, + "match_count": self.match_count(), } diff --git a/tournaments/models/match.py b/tournaments/models/match.py index a3c09b7..7697552 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -118,7 +118,8 @@ class Match(models.Model): if self.court: court = f"Terrain {self.court}" - livematch = LiveMatch(title, date, duration, court, self.started()) + ended = self.end_date is not None + livematch = LiveMatch(title, date, duration, court, self.started(), ended) for team_score in self.sorted_team_scores(): image = team_score.team_registration.logo @@ -169,13 +170,14 @@ class Team: } class LiveMatch: - def __init__(self, title, date, duration, court, started): + def __init__(self, title, date, duration, court, started, ended): self.title = title self.date = date self.teams = [] self.duration = duration self.court = court self.started = started + self.ended = ended def add_team(self, team): self.teams.append(team) @@ -188,6 +190,7 @@ class LiveMatch: "duration": self.duration, "court": self.court, "started": self.started, + "ended": self.ended, } def has_walk_out(self): diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index 7192dbf..be01bd1 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -2,6 +2,7 @@ from django.db import models from django.db.models.sql.query import Q from . import Tournament, GroupStage, Match import uuid +from django.utils import timezone class TeamRegistration(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) @@ -38,7 +39,8 @@ class TeamRegistration(models.Model): def next_match(self): all_matches = [ts.match for ts in self.teamscore_set.all()] - all_matches = sorted(all_matches, key=lambda m: m.start_date) + now = timezone.now() + all_matches = sorted(all_matches, key=lambda m: m.start_date if m.start_date is not None else now) matches = [m for m in all_matches if m.end_date is None] if matches: return matches[0] diff --git a/tournaments/templates/tournaments/group_stage_cell.html b/tournaments/templates/tournaments/group_stage_cell.html index 96e0105..53c05de 100644 --- a/tournaments/templates/tournaments/group_stage_cell.html +++ b/tournaments/templates/tournaments/group_stage_cell.html @@ -1,61 +1,44 @@ {% load static %} -
-
- -
- - -
- -
- - {% for team in group_stage.teams %} - -
-
- {% for name in team.names %} -
- {{ name }} -
- {% endfor %} -
-
-
{{ team.wins_losses }}
-
{{ team.formatted_diff }}
-
-
- - - {% endfor %} - -
- -
- - - -
- -
+
+
+ +
+ + +
+ +
+ + {% for team in group_stage.teams %} + +
+
+ {% for name in team.names %} +
+ {{ name }}
+ {% endfor %} +
+
+ {% if team.match_count == 0 %} +
{{ team.weight }}
+ {% else %} +
{{ team.wins_losses }}
+
{{ team.formatted_diff }}
+ {% endif %} +
+
+ + {% endfor %} + +
+ +
+ + + +
+ +
+
diff --git a/tournaments/templates/tournaments/match_cell.html b/tournaments/templates/tournaments/match_cell.html index 95a5e1d..69cd4c0 100644 --- a/tournaments/templates/tournaments/match_cell.html +++ b/tournaments/templates/tournaments/match_cell.html @@ -50,7 +50,11 @@ {{ match.duration }} {% endif %} - +
diff --git a/tournaments/templates/tournaments/tournaments.html b/tournaments/templates/tournaments/tournaments.html index 200971c..86043f5 100644 --- a/tournaments/templates/tournaments/tournaments.html +++ b/tournaments/templates/tournaments/tournaments.html @@ -17,27 +17,36 @@ {% if live or future %}
+ + {% if live %}
+
- {% if live %} {% for tournament in live %} {% include 'tournaments/tournament_row.html' %} {% endfor %} - {% endif %} +
+
- {% if future %} + {% endif %} - + {% if future %} +
+ +
+ + {% for tournament in future %} {% include 'tournaments/tournament_row.html' %} {% endfor %} - {% endif %}
+ {% endif %} +
{% endif %}