diff --git a/tournaments/models/round.py b/tournaments/models/round.py index 6a69339..4b3c325 100644 --- a/tournaments/models/round.py +++ b/tournaments/models/round.py @@ -6,11 +6,14 @@ class Round(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE) index = models.IntegerField(default=0) - loser = models.ForeignKey('self', blank=True, null=True, on_delete=models.CASCADE) + loser = models.ForeignKey('self', blank=True, null=True, on_delete=models.CASCADE, related_name='children') format = models.IntegerField(default=FederalMatchCategory.NINE_GAMES, choices=FederalMatchCategory.choices, null=True, blank=True) def __str__(self): - return f"{self.tournament.name} - {self.name()}" + if self.loser: + return f"{self.tournament.name} - Loser bracket of : {self.name()}" + else: + return f"{self.tournament.name} - {self.name()}" # def stage_call(self): # stage_call = StageCall(f"1/{self.index}") @@ -23,12 +26,16 @@ class Round(models.Model): # return stage_call def name(self): - if self.index == 0: - return "Finale" - elif self.index == 1: - return "Demi-Finales" - elif self.index == 2: - return "Quarts de finale" + if self.loser: + parent = self.loser.name() + return f"Matchs de classement [{parent}]" else: - squared = 2 ** self.index - return f"{squared}ème" + if self.index == 0: + return "Finale" + elif self.index == 1: + return "Demi-Finales" + elif self.index == 2: + return "Quarts de finale" + else: + squared = 2 ** self.index + return f"{squared}ème" diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 0b1d92f..b39f96d 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -70,46 +70,63 @@ class Tournament(models.Model): summons.sort(key=lambda s: s.weight) return summons - def live_matches(self, broadcasted, group_stage_id, round_id): + def match_groups(self, broadcasted, group_stage_id, round_id): - matches = [] + match_groups = [] if group_stage_id: - matches = self.group_stage_matches(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)) elif round_id: - matches = self.round_matches(round_id) + round = self.round_set.filter(id=round_id).first() + match_groups = self.round_match_groups(round, broadcasted) else: - matches = self.all_matches() + match_groups = self.all_groups(broadcasted) - # matches = [m for m in matches if m.broadcasted==True] - if not broadcasted: - matches = [m for m in matches if len(m.team_scores.all()) > 0] - - matches.sort(key=lambda m: m.order) + return match_groups - return [match.live_match() for match in matches] - # return map(lambda match: match.live_match(), matches) - - def all_matches(self): - matches = [] + def all_groups(self, broadcasted): + groups = [] for group_stage in self.groupstage_set.all(): - for match in group_stage.match_set.all(): - matches.append(match) + group = self.group_stage_match_group(group_stage, broadcasted) + groups.append(group) for round in self.round_set.all(): - for match in round.match_set.all(): - matches.append(match) - return matches + groups = 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_matches(self, group_stage_id): - group_stage = self.groupstage_set.filter(id=group_stage_id).first() - return group_stage.match_set.all() + def round_match_groups(self, round, broadcasted): + 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) - def round_matches(self, round_id): - round = self.round_set.filter(id=round_id).first() - return round.match_set.all() + 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.sort(key=lambda m: m.order) + live_matches = [match.live_match() for match in matches] + return MatchGroup(name, live_matches) def live_group_stages(self): return [gs.live_group_stages() for gs in self.groupstage_set.all()] +class MatchGroup: + def __init__(self, name, matches): + self.name = name + self.matches = matches + + def add_match(self, match): + self.matches.append(match) + + def add_matches(self, matches): + self.matches = matches + class TeamSummon: def __init__(self, names, date, weight, stage, image): self.names = names diff --git a/tournaments/static/tournaments/css/style.css b/tournaments/static/tournaments/css/style.css index 9e005a5..9b72871 100644 --- a/tournaments/static/tournaments/css/style.css +++ b/tournaments/static/tournaments/css/style.css @@ -55,6 +55,16 @@ a:hover { color: #f39200; } +nav { + display: flex; /* Use flexbox */ + flex-wrap: wrap; /* Allow items to wrap onto multiple lines */ + justify-content: flex-start; /* Align items to the start */ +} + +nav a { + margin-right: 6px; /* Adjust the horizontal spacing between elements */ +} + /* a { color: #707070; padding: 8px 12px; @@ -374,6 +384,15 @@ tr { .vertical-padding { padding: 8px 0px; } +.topmargin5 { + margin-top: 5px; +} +.topmargin10 { + margin-top: 10px; +} +.topmargin20 { + margin-top: 20px; +} .tight { line-height: 1.1; diff --git a/tournaments/templates/tournaments/matches.html b/tournaments/templates/tournaments/matches.html index 235b450..c8d7a3c 100644 --- a/tournaments/templates/tournaments/matches.html +++ b/tournaments/templates/tournaments/matches.html @@ -9,24 +9,31 @@ {% include 'tournaments/tournament_navigation.html' %} {% if rounds or group_stages %} -