diff --git a/tournaments/models/round.py b/tournaments/models/round.py index f5b9144..627efaa 100644 --- a/tournaments/models/round.py +++ b/tournaments/models/round.py @@ -15,16 +15,6 @@ class Round(models.Model): else: return f"{self.tournament.name} - {self.name()}" - # def stage_call(self): - # stage_call = StageCall(f"1/{self.index}") - # for match in self.match_set.all(): - # names = map(lambda ts: ts.player_names(), match.teamstate_set.all()) - # if names: - # team_call = TeamCall(names, match.formatted_start_date) - # stage_call.add_team(team_call) - - # return stage_call - def name(self): if self.loser: return "Matchs de classement" @@ -50,3 +40,8 @@ class Round(models.Model): matches.extend(child_matches) matches.extend(child.ranking_matches(hide_empty_matches)) return matches + + def all_matches(self): + matches = self.match_set.all() + matches.extend(self.ranking_matches(True)) + return matches diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 30e9cbd..7ee277a 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -19,7 +19,6 @@ class Tournament(models.Model): bracket_sort_mode = models.IntegerField(default=0) group_stage_count = models.IntegerField(default=0) rank_source_date = models.DateTimeField(null=True, blank=True) - # custom_name = models.CharField(max_length=100, null=True, blank=True) day_duration = models.IntegerField(default=0) team_count = models.IntegerField(default=0) team_sorting = models.IntegerField(default=0) @@ -34,7 +33,6 @@ class Tournament(models.Model): prioritize_club_members = models.BooleanField() qualified_per_group_stage = models.IntegerField(default=0) teams_per_group_stage = models.IntegerField(default=0) - #estimated_end_date = models.DateTimeField(null=True, blank=True) def __str__(self): if self.name: @@ -133,6 +131,50 @@ class Tournament(models.Model): def live_group_stages(self): return [gs.live_group_stages() for gs in self.groupstage_set.all()] + def live_matches(self): + + matches = [] + last_started_match = self.last_match() + current_round = last_started_match.round + if current_round: + + previous_round = self.round_for_index(current_round.index - 1) + if previous_round: + matches.extend(current_round.all_matches()) + matches.extend(previous_round.all_matches()) + else: + matches.extend(current_round.all_matches()) + # todo on veut les matchs du round et les poules, comment ça marche ? + # dans le monde idéal on veut afficher plusieurs pages de plusieurs types différents + # est-ce que je construis un json avec des types différents dans un même array ? + # je veux pas que des types différents apparaissent sur une même page + else: + matches = self.group_stages_matches() + + return matches + + def last_match(self): + matches = [] + for round in self.round_set.all(): + matches.extend(round.match_set.all()) + for group_stage in self.groupstage_set.all(): + matches.extend(group_stage.match_set.all()) + + matches = [m for m in matches if m.start_date] + matches.sort(key=lambda m: -m.start_date) + return matches[0] + + def round_for_index(self, index): + return self.round_set.filter(index=index).first() + + def group_stages_matches(self): + matches = [] + for group_stage in self.groupstage_set.all(): + matches.extend(group_stage.match_set.all()) + matches = [m for m in matches if m.should_appear()] + matches.sort(key=lambda m: -m.start_date) + return matches + class MatchGroup: def __init__(self, name, matches): self.name = name @@ -157,10 +199,10 @@ class TeamSummon: return formats.date_format(timezoned_datetime, format='H:i') def to_dict(self): - return { - "names": self.names, - "date": self.formatted_date(), - "weight": self.weight, - "stage": self.stage, - "image": self.image, - } + return { + "names": self.names, + "date": self.formatted_date(), + "weight": self.weight, + "stage": self.stage, + "image": self.image, + }