|
|
|
|
@ -66,13 +66,6 @@ class Tournament(BaseModel): |
|
|
|
|
initial_seed_round = models.IntegerField(default=0) |
|
|
|
|
initial_seed_count = models.IntegerField(default=0) |
|
|
|
|
|
|
|
|
|
def get_child_models(self): |
|
|
|
|
return { |
|
|
|
|
'Round': 'round_set', |
|
|
|
|
'GroupStage': 'groupstage_set', |
|
|
|
|
'TeamRegistration': 'teamregistration_set' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
|
if self.name: |
|
|
|
|
return self.name |
|
|
|
|
@ -250,7 +243,7 @@ class Tournament(BaseModel): |
|
|
|
|
summons.append(summon) |
|
|
|
|
else: |
|
|
|
|
print('>>> team_summons') |
|
|
|
|
for team_registration in self.teamregistration_set.all(): |
|
|
|
|
for team_registration in self.team_registrations.all(): |
|
|
|
|
if team_registration.is_valid_for_summon(): |
|
|
|
|
next_match = team_registration.next_match() |
|
|
|
|
if next_match and next_match.start_date is not None: |
|
|
|
|
@ -264,7 +257,7 @@ class Tournament(BaseModel): |
|
|
|
|
return summons |
|
|
|
|
|
|
|
|
|
def has_summons(self): |
|
|
|
|
for team_registration in self.teamregistration_set.all(): |
|
|
|
|
for team_registration in self.team_registrations.all(): |
|
|
|
|
if team_registration.is_valid_for_summon(): |
|
|
|
|
next_match = team_registration.next_match() |
|
|
|
|
if next_match and next_match.start_date is not None: |
|
|
|
|
@ -273,7 +266,7 @@ class Tournament(BaseModel): |
|
|
|
|
|
|
|
|
|
def rankings(self): |
|
|
|
|
rankings = [] |
|
|
|
|
for team_registration in self.teamregistration_set.all(): |
|
|
|
|
for team_registration in self.team_registrations.all(): |
|
|
|
|
if team_registration.walk_out is False and team_registration.final_ranking is not None: |
|
|
|
|
names = team_registration.team_names() |
|
|
|
|
ranking = team_registration.final_ranking |
|
|
|
|
@ -296,7 +289,7 @@ class Tournament(BaseModel): |
|
|
|
|
closed_registration_date = self.closed_registration_date |
|
|
|
|
# print(f"Closed registration date: {closed_registration_date}") |
|
|
|
|
|
|
|
|
|
for team_registration in self.teamregistration_set.all(): |
|
|
|
|
for team_registration in self.team_registrations.all(): |
|
|
|
|
# print(f"Processing team registration: {team_registration}") |
|
|
|
|
is_valid = False |
|
|
|
|
if closed_registration_date is not None and team_registration.registration_date is not None and team_registration.registration_date <= closed_registration_date: |
|
|
|
|
@ -413,10 +406,10 @@ class Tournament(BaseModel): |
|
|
|
|
|
|
|
|
|
match_groups = [] |
|
|
|
|
if group_stage_id: |
|
|
|
|
group_stage = self.groupstage_set.filter(id=group_stage_id).first() |
|
|
|
|
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.round_set.filter(id=round_id).first() |
|
|
|
|
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: |
|
|
|
|
@ -428,11 +421,11 @@ class Tournament(BaseModel): |
|
|
|
|
groups = [] |
|
|
|
|
|
|
|
|
|
if self.display_matches(): |
|
|
|
|
for round in self.round_set.filter(parent=None, group_stage_loser_bracket=False).all().order_by('index'): |
|
|
|
|
for round in self.rounds.filter(parent=None, group_stage_loser_bracket=False).all().order_by('index'): |
|
|
|
|
groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) |
|
|
|
|
|
|
|
|
|
if self.display_group_stages(): |
|
|
|
|
for round in self.round_set.filter(parent=None, group_stage_loser_bracket=True).all().order_by('index'): |
|
|
|
|
for round in self.group_stages.all().order_by('index'): |
|
|
|
|
groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) |
|
|
|
|
|
|
|
|
|
ordered = sorted(self.get_computed_group_stage(), key=lambda s: (-s.step, s.index)) |
|
|
|
|
@ -444,7 +437,7 @@ class Tournament(BaseModel): |
|
|
|
|
return groups |
|
|
|
|
|
|
|
|
|
def group_stage_match_group(self, group_stage, broadcasted, hide_empty_matches): |
|
|
|
|
matches = group_stage.match_set.all() |
|
|
|
|
matches = group_stage.matches.all() |
|
|
|
|
if hide_empty_matches: |
|
|
|
|
matches = [m for m in matches if m.should_appear()] |
|
|
|
|
else: |
|
|
|
|
@ -460,7 +453,7 @@ class Tournament(BaseModel): |
|
|
|
|
def round_match_groups(self, round, broadcasted, hide_empty_matches): |
|
|
|
|
groups = [] |
|
|
|
|
|
|
|
|
|
matches = round.match_set.order_by('index').all() |
|
|
|
|
matches = round.matches.order_by('index').all() |
|
|
|
|
if hide_empty_matches: |
|
|
|
|
matches = [m for m in matches if m.should_appear()] |
|
|
|
|
else: |
|
|
|
|
@ -515,7 +508,7 @@ class Tournament(BaseModel): |
|
|
|
|
|
|
|
|
|
def get_computed_group_stage(self): |
|
|
|
|
# Get all group stages and sort by step (descending) and index (ascending) |
|
|
|
|
group_stages = self.groupstage_set.all().order_by('-step', 'index') |
|
|
|
|
group_stages = self.group_stages.all().order_by('-step', 'index') |
|
|
|
|
|
|
|
|
|
# List to collect live group stages from finished steps |
|
|
|
|
filtered = [] |
|
|
|
|
@ -523,7 +516,7 @@ class Tournament(BaseModel): |
|
|
|
|
for group_stage in group_stages: |
|
|
|
|
if group_stage.step > 0: |
|
|
|
|
# Check the previous step's group stages |
|
|
|
|
previous_step_group_stages = self.groupstage_set.filter(step=group_stage.step - 1) |
|
|
|
|
previous_step_group_stages = self.group_stages.filter(step=group_stage.step - 1) |
|
|
|
|
|
|
|
|
|
# Check if all previous step group stages are completed |
|
|
|
|
if all(gs.is_completed() for gs in previous_step_group_stages): |
|
|
|
|
@ -535,7 +528,7 @@ class Tournament(BaseModel): |
|
|
|
|
return filtered |
|
|
|
|
|
|
|
|
|
def get_previous_live_group_stages(self, step): |
|
|
|
|
previous_step_group_stages = self.groupstage_set.filter(step=step).order_by('index') |
|
|
|
|
previous_step_group_stages = self.group_stages.filter(step=step).order_by('index') |
|
|
|
|
return [gs.live_group_stages() for gs in previous_step_group_stages] |
|
|
|
|
|
|
|
|
|
def last_group_stage_step(self): |
|
|
|
|
@ -605,7 +598,7 @@ class Tournament(BaseModel): |
|
|
|
|
matches = [] |
|
|
|
|
group_stages = [] |
|
|
|
|
|
|
|
|
|
if len(self.groupstage_set.all()) > 0 and self.no_bracket_match_has_started(): |
|
|
|
|
if len(self.group_stages.all()) > 0 and self.no_bracket_match_has_started(): |
|
|
|
|
group_stages = [gs.live_group_stages() for gs in self.last_group_stage_step()] |
|
|
|
|
matches = self.broadcasted_group_stages_matches() |
|
|
|
|
first_round = self.first_round() |
|
|
|
|
@ -642,18 +635,18 @@ class Tournament(BaseModel): |
|
|
|
|
|
|
|
|
|
def no_bracket_match_has_started(self): |
|
|
|
|
matches = [] |
|
|
|
|
for round in self.round_set.all(): |
|
|
|
|
for match in round.match_set.all(): |
|
|
|
|
for round in self.rounds.all(): |
|
|
|
|
for match in round.matches.all(): |
|
|
|
|
if match.started(): |
|
|
|
|
return False |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
def all_matches(self, hide_empty_matches): |
|
|
|
|
matches = [] |
|
|
|
|
for round in self.round_set.all(): |
|
|
|
|
for round in self.rounds.all(): |
|
|
|
|
matches.extend(round.all_matches(hide_empty_matches)) |
|
|
|
|
for group_stage in self.groupstage_set.all(): |
|
|
|
|
matches.extend(group_stage.match_set.all()) |
|
|
|
|
for group_stage in self.group_stages.all(): |
|
|
|
|
matches.extend(group_stage.matches.all()) |
|
|
|
|
|
|
|
|
|
matches = [m for m in matches if m.should_appear()] |
|
|
|
|
|
|
|
|
|
@ -661,12 +654,12 @@ class Tournament(BaseModel): |
|
|
|
|
|
|
|
|
|
def group_stage_matches(self): |
|
|
|
|
matches = [] |
|
|
|
|
for group_stage in self.groupstage_set.all(): |
|
|
|
|
matches.extend(group_stage.match_set.all()) |
|
|
|
|
for group_stage in self.group_stages.all(): |
|
|
|
|
matches.extend(group_stage.matches.all()) |
|
|
|
|
return matches |
|
|
|
|
|
|
|
|
|
def group_stages_running(self): |
|
|
|
|
if len(self.groupstage_set.all()) > 0: |
|
|
|
|
if len(self.group_stages.all()) > 0: |
|
|
|
|
# check le debut des match de Round |
|
|
|
|
matches = self.group_stage_matches() |
|
|
|
|
running_group_stage_matches = [m for m in matches if m.end_date is None] |
|
|
|
|
@ -701,7 +694,7 @@ class Tournament(BaseModel): |
|
|
|
|
if round_root_index == 0: |
|
|
|
|
return last_finished_match.round |
|
|
|
|
else: |
|
|
|
|
round = self.round_set.filter(parent=None,index=round_root_index-1).first() |
|
|
|
|
round = self.rounds.filter(parent=None,index=round_root_index-1).first() |
|
|
|
|
if round: |
|
|
|
|
return round |
|
|
|
|
else: |
|
|
|
|
@ -718,10 +711,10 @@ class Tournament(BaseModel): |
|
|
|
|
return matches[0] if matches else None |
|
|
|
|
|
|
|
|
|
def round_for_index(self, index): |
|
|
|
|
return self.round_set.filter(index=index, parent=None).first() |
|
|
|
|
return self.rounds.filter(index=index, parent=None).first() |
|
|
|
|
|
|
|
|
|
def first_round(self): |
|
|
|
|
main_rounds = list(self.round_set.filter(parent=None)) |
|
|
|
|
main_rounds = list(self.rounds.filter(parent=None)) |
|
|
|
|
main_rounds.sort(key=lambda r: r.index, reverse=True) |
|
|
|
|
return main_rounds[0] if main_rounds else None |
|
|
|
|
|
|
|
|
|
@ -730,11 +723,11 @@ class Tournament(BaseModel): |
|
|
|
|
group_stages = self.elected_broadcast_group_stages() |
|
|
|
|
group_stages.sort(key=lambda gs: (gs.index, gs.start_date is None, gs.start_date)) |
|
|
|
|
for group_stage in group_stages: |
|
|
|
|
matches.extend(group_stage.match_set.all()) |
|
|
|
|
matches.extend(group_stage.matches.all()) |
|
|
|
|
matches = [m for m in matches if m.should_appear()] |
|
|
|
|
matches.sort(key=lambda m: (m.start_date is None, m.end_date is not None, m.start_date, m.index)) |
|
|
|
|
|
|
|
|
|
group_stage_loser_bracket = list(self.round_set.filter(parent=None, group_stage_loser_bracket=True).all()) |
|
|
|
|
group_stage_loser_bracket = list(self.rounds.filter(parent=None, group_stage_loser_bracket=True).all()) |
|
|
|
|
if len(group_stage_loser_bracket) > 0: |
|
|
|
|
loser_matches = group_stage_loser_bracket[0].all_matches(True) |
|
|
|
|
loser_matches = [m for m in loser_matches if m.should_appear()] |
|
|
|
|
@ -744,7 +737,7 @@ class Tournament(BaseModel): |
|
|
|
|
return matches |
|
|
|
|
|
|
|
|
|
def elected_broadcast_group_stages(self): |
|
|
|
|
group_stages = list(self.last_group_stage_step()) |
|
|
|
|
group_stages = list(self.group_stages()) |
|
|
|
|
started = [gs for gs in group_stages if gs.starts_soon()] |
|
|
|
|
if len(started) > 0: |
|
|
|
|
return started |
|
|
|
|
@ -779,7 +772,7 @@ class Tournament(BaseModel): |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
def has_team_registrations(self): |
|
|
|
|
return len(self.teamregistration_set.all()) > 0 |
|
|
|
|
return len(self.team_registrations.all()) > 0 |
|
|
|
|
|
|
|
|
|
def display_summons(self): |
|
|
|
|
if self.end_date is not None: |
|
|
|
|
@ -793,7 +786,7 @@ class Tournament(BaseModel): |
|
|
|
|
def display_group_stages(self): |
|
|
|
|
if self.end_date is not None: |
|
|
|
|
return True |
|
|
|
|
if len(self.groupstage_set.all()) == 0: |
|
|
|
|
if len(self.group_stages.all()) == 0: |
|
|
|
|
return False |
|
|
|
|
if self.publish_group_stages: |
|
|
|
|
return True |
|
|
|
|
@ -805,7 +798,7 @@ class Tournament(BaseModel): |
|
|
|
|
return timezone.now() >= first_group_stage_start_date |
|
|
|
|
|
|
|
|
|
def group_stage_start_date(self): |
|
|
|
|
group_stages = [gs for gs in self.groupstage_set.all() if gs.start_date is not None] |
|
|
|
|
group_stages = [gs for gs in self.group_stages.all() if gs.start_date is not None] |
|
|
|
|
if len(group_stages) == 0: |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
@ -842,7 +835,7 @@ class Tournament(BaseModel): |
|
|
|
|
|
|
|
|
|
def bracket_matches(self): |
|
|
|
|
matches = [] |
|
|
|
|
for round in self.round_set.all(): |
|
|
|
|
for round in self.rounds.all(): |
|
|
|
|
matches.extend(round.all_matches(False)) |
|
|
|
|
return matches |
|
|
|
|
|
|
|
|
|
@ -882,7 +875,7 @@ class Tournament(BaseModel): |
|
|
|
|
return self.hide_teams_weight |
|
|
|
|
|
|
|
|
|
def is_build_and_not_empty(self): |
|
|
|
|
return (len(self.groupstage_set.all()) > 0 or len(self.round_set.all()) > 0) and len(self.teamregistration_set.all()) >= 4 |
|
|
|
|
return (len(self.group_stages.all()) > 0 or len(self.rounds.all()) > 0) and len(self.team_registrations.all()) >= 4 |
|
|
|
|
|
|
|
|
|
def day_duration_formatted(self): |
|
|
|
|
return plural_format("jour", self.day_duration) |
|
|
|
|
@ -894,7 +887,7 @@ class Tournament(BaseModel): |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
def has_all_group_stages_started(self): |
|
|
|
|
for group_stage in self.groupstage_set.all(): |
|
|
|
|
for group_stage in self.group_stages.all(): |
|
|
|
|
if group_stage.has_at_least_one_started_match() is False: |
|
|
|
|
return False |
|
|
|
|
return True |
|
|
|
|
|