|
|
|
@ -401,7 +401,8 @@ class Tournament(models.Model): |
|
|
|
for round in self.round_set.filter(parent=None, group_stage_loser_bracket=True).all().order_by('index'): |
|
|
|
for round in self.round_set.filter(parent=None, group_stage_loser_bracket=True).all().order_by('index'): |
|
|
|
groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) |
|
|
|
groups.extend(self.round_match_groups(round, broadcasted, hide_empty_matches=True)) |
|
|
|
|
|
|
|
|
|
|
|
for group_stage in self.groupstage_set.all().order_by('index'): |
|
|
|
ordered = sorted(self.get_computed_group_stage(), key=lambda s: (-s.step, s.index)) |
|
|
|
|
|
|
|
for group_stage in ordered: |
|
|
|
group = self.group_stage_match_group(group_stage, broadcasted, hide_empty_matches=True) |
|
|
|
group = self.group_stage_match_group(group_stage, broadcasted, hide_empty_matches=True) |
|
|
|
if group: |
|
|
|
if group: |
|
|
|
groups.append(group) |
|
|
|
groups.append(group) |
|
|
|
@ -455,10 +456,47 @@ class Tournament(models.Model): |
|
|
|
return MatchGroup(name, live_matches) |
|
|
|
return MatchGroup(name, live_matches) |
|
|
|
|
|
|
|
|
|
|
|
def live_group_stages(self): |
|
|
|
def live_group_stages(self): |
|
|
|
group_stages = list(self.groupstage_set.all()) |
|
|
|
group_stages = self.get_computed_group_stage() |
|
|
|
group_stages.sort(key=lambda gs: gs.index) |
|
|
|
|
|
|
|
return [gs.live_group_stages() for gs in group_stages] |
|
|
|
return [gs.live_group_stages() for gs in group_stages] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# List to collect live group stages from finished steps |
|
|
|
|
|
|
|
filtered = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check if all previous step group stages are completed |
|
|
|
|
|
|
|
if all(gs.is_completed() for gs in previous_step_group_stages): |
|
|
|
|
|
|
|
filtered.append(group_stage) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
# Always include step 0 |
|
|
|
|
|
|
|
filtered.append(group_stage) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return filtered |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_previous_live_group_stages(self, step): |
|
|
|
|
|
|
|
previous_step_group_stages = self.groupstage_set.filter(step=step).order_by('index') |
|
|
|
|
|
|
|
return [gs.live_group_stages() for gs in previous_step_group_stages] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def last_group_stage_step(self): |
|
|
|
|
|
|
|
live_group_stages = self.get_computed_group_stage() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Filter to find the last running step |
|
|
|
|
|
|
|
last_running_step = max(gs.step for gs in live_group_stages) if live_group_stages else None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if last_running_step is not None: |
|
|
|
|
|
|
|
# Get only group stages from the last running step |
|
|
|
|
|
|
|
group_stages_last_step = [gs for gs in live_group_stages if gs.step == last_running_step] |
|
|
|
|
|
|
|
return group_stages_last_step |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
return [] |
|
|
|
|
|
|
|
|
|
|
|
def broadcast_content(self): |
|
|
|
def broadcast_content(self): |
|
|
|
|
|
|
|
|
|
|
|
matches, group_stages = self.broadcasted_matches_and_group_stages() |
|
|
|
matches, group_stages = self.broadcasted_matches_and_group_stages() |
|
|
|
@ -514,7 +552,7 @@ class Tournament(models.Model): |
|
|
|
group_stages = [] |
|
|
|
group_stages = [] |
|
|
|
|
|
|
|
|
|
|
|
if len(self.groupstage_set.all()) > 0 and self.no_bracket_match_has_started(): |
|
|
|
if len(self.groupstage_set.all()) > 0 and self.no_bracket_match_has_started(): |
|
|
|
group_stages = self.live_group_stages() |
|
|
|
group_stages = [gs.live_group_stages() for gs in self.last_group_stage_step()] |
|
|
|
matches = self.broadcasted_group_stages_matches() |
|
|
|
matches = self.broadcasted_group_stages_matches() |
|
|
|
first_round = self.first_round() |
|
|
|
first_round = self.first_round() |
|
|
|
if first_round and self.has_all_group_stages_started(): |
|
|
|
if first_round and self.has_all_group_stages_started(): |
|
|
|
@ -535,7 +573,7 @@ class Tournament(models.Model): |
|
|
|
matches.extend(previous_round.get_matches_recursive(True)) |
|
|
|
matches.extend(previous_round.get_matches_recursive(True)) |
|
|
|
else: |
|
|
|
else: |
|
|
|
matches.extend(current_round.all_matches(True)) |
|
|
|
matches.extend(current_round.all_matches(True)) |
|
|
|
group_stages = self.live_group_stages() |
|
|
|
group_stages = [gs.live_group_stages() for gs in self.last_group_stage_step()] |
|
|
|
|
|
|
|
|
|
|
|
return matches, group_stages |
|
|
|
return matches, group_stages |
|
|
|
|
|
|
|
|
|
|
|
@ -626,7 +664,7 @@ class Tournament(models.Model): |
|
|
|
return matches |
|
|
|
return matches |
|
|
|
|
|
|
|
|
|
|
|
def elected_broadcast_group_stages(self): |
|
|
|
def elected_broadcast_group_stages(self): |
|
|
|
group_stages = list(self.groupstage_set.all()) |
|
|
|
group_stages = list(self.last_group_stage_step()) |
|
|
|
started = [gs for gs in group_stages if gs.starts_soon()] |
|
|
|
started = [gs for gs in group_stages if gs.starts_soon()] |
|
|
|
if len(started) > 0: |
|
|
|
if len(started) > 0: |
|
|
|
return started |
|
|
|
return started |
|
|
|
|