|
|
|
|
@ -1008,6 +1008,43 @@ def get_bracket(tournament, parent_round=None, double_butterfly_mode=False, disp |
|
|
|
|
# Add first half of each round (from last to semi-finals) |
|
|
|
|
for round in main_rounds: |
|
|
|
|
matches = round.match_set.filter(disabled=False).order_by('index') |
|
|
|
|
next_round = main_rounds.filter(index=round.index - 1).first() |
|
|
|
|
if next_round: |
|
|
|
|
next_round_matches = next_round.match_set.filter(disabled=False).order_by('index') |
|
|
|
|
else: |
|
|
|
|
next_round_matches = [] |
|
|
|
|
|
|
|
|
|
if len(matches) < len(next_round_matches): |
|
|
|
|
all_matches = round.match_set.order_by('index') |
|
|
|
|
filtered_matches = [] |
|
|
|
|
|
|
|
|
|
# Process matches in pairs |
|
|
|
|
i = 0 |
|
|
|
|
while i < len(all_matches): |
|
|
|
|
# Get the current match and its pair (if available) |
|
|
|
|
current_match = all_matches[i] |
|
|
|
|
pair_match = all_matches[i+1] if i+1 < len(all_matches) else None |
|
|
|
|
|
|
|
|
|
# Only filter out the pair if both matches are disabled |
|
|
|
|
if current_match.disabled and pair_match and pair_match.disabled: |
|
|
|
|
# Skip one of the matches in the pair |
|
|
|
|
filtered_matches.append(current_match) |
|
|
|
|
pass |
|
|
|
|
else: |
|
|
|
|
# Keep the current match |
|
|
|
|
if current_match.disabled == False: |
|
|
|
|
filtered_matches.append(current_match) |
|
|
|
|
# If there's a pair match, keep it too |
|
|
|
|
if pair_match and pair_match.disabled == False: |
|
|
|
|
filtered_matches.append(pair_match) |
|
|
|
|
|
|
|
|
|
# Move to the next pair |
|
|
|
|
i += 2 |
|
|
|
|
|
|
|
|
|
# Replace the matches list with our filtered list |
|
|
|
|
matches = filtered_matches |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if matches: |
|
|
|
|
if len(matches) > 1 and double_butterfly_mode: |
|
|
|
|
@ -1035,6 +1072,42 @@ def get_bracket(tournament, parent_round=None, double_butterfly_mode=False, disp |
|
|
|
|
if double_butterfly_mode: |
|
|
|
|
for round in main_rounds_reversed: |
|
|
|
|
matches = round.match_set.filter(disabled=False).order_by('index') |
|
|
|
|
next_round = main_rounds_reversed.filter(index=round.index - 1).first() |
|
|
|
|
if next_round: |
|
|
|
|
next_round_matches = next_round.match_set.filter(disabled=False).order_by('index') |
|
|
|
|
else: |
|
|
|
|
next_round_matches = [] |
|
|
|
|
|
|
|
|
|
if len(matches) < len(next_round_matches): |
|
|
|
|
all_matches = round.match_set.order_by('index') |
|
|
|
|
filtered_matches = [] |
|
|
|
|
|
|
|
|
|
# Process matches in pairs |
|
|
|
|
i = 0 |
|
|
|
|
while i < len(all_matches): |
|
|
|
|
# Get the current match and its pair (if available) |
|
|
|
|
current_match = all_matches[i] |
|
|
|
|
pair_match = all_matches[i+1] if i+1 < len(all_matches) else None |
|
|
|
|
|
|
|
|
|
# Only filter out the pair if both matches are disabled |
|
|
|
|
if current_match.disabled and pair_match and pair_match.disabled: |
|
|
|
|
# Skip one of the matches in the pair |
|
|
|
|
filtered_matches.append(current_match) |
|
|
|
|
pass |
|
|
|
|
else: |
|
|
|
|
# Keep the current match |
|
|
|
|
if current_match.disabled == False: |
|
|
|
|
filtered_matches.append(current_match) |
|
|
|
|
# If there's a pair match, keep it too |
|
|
|
|
if pair_match and pair_match.disabled == False: |
|
|
|
|
filtered_matches.append(pair_match) |
|
|
|
|
|
|
|
|
|
# Move to the next pair |
|
|
|
|
i += 2 |
|
|
|
|
|
|
|
|
|
# Replace the matches list with our filtered list |
|
|
|
|
matches = filtered_matches |
|
|
|
|
|
|
|
|
|
if matches: |
|
|
|
|
if len(matches) > 1: |
|
|
|
|
midpoint = int(len(matches) / 2) |
|
|
|
|
|