General clean-up

This commit is contained in:
2026-02-22 14:01:47 +01:00 Verified
parent 7ce44979b9
commit 7d04ceb2a3
17 changed files with 401 additions and 231 deletions
+24 -8
View File
@@ -6,7 +6,7 @@ from uuid import uuid4
from sqlalchemy.orm import Session
from . import models
from .constants import MatchStatus, TournamentTypes
from .constants import BracketTypes, MatchStatus, TournamentTypes
from .core.brackets import BracketGenerator
@@ -181,6 +181,25 @@ def advance_winner(db: Session, match: models.Match, winner_id: int):
loser_id = match.p1_team_id if match.p1_team_id != winner_id else match.p2_team_id
if (
match.bracket_type == BracketTypes.FINALS
and match.winner_next_match
and match.winner_next_match.bracket_type == BracketTypes.FINALS
):
if winner_id == match.p1_team_id:
reset_match = match.winner_next_match
if reset_match.winner_team_id:
undo_advancement(db, reset_match)
reset_match.winner_team_id = None
reset_match.sets = []
reset_match.p1_team_id = None
reset_match.p2_team_id = None
reset_match.status = MatchStatus.SCHEDULED
db.add(reset_match)
db.commit()
return
def update_next_match(
next_match: models.Match, team_id: int, target_slot: int | None
):
@@ -214,9 +233,7 @@ def undo_advancement(db: Session, match: models.Match):
winner_id = match.winner_team_id
loser_id = match.p1_team_id if match.p1_team_id != winner_id else match.p2_team_id
def clear_from_next(
next_match: models.Match, team_id: int, target_slot: int | None
):
def clear_from_next(next_match: models.Match, target_slot: int | None):
if not next_match or target_slot is None:
return
@@ -230,11 +247,10 @@ def undo_advancement(db: Session, match: models.Match):
elif target_slot == 1:
next_match.p2_team_id = None
if next_match.status == MatchStatus.PENDING:
next_match.status = MatchStatus.SCHEDULED
next_match.status = MatchStatus.SCHEDULED
db.add(next_match)
clear_from_next(match.winner_next_match, winner_id, match.winner_next_match_slot)
clear_from_next(match.winner_next_match, match.winner_next_match_slot)
if match.loser_next_match and loser_id:
clear_from_next(match.loser_next_match, loser_id, match.loser_next_match_slot)
clear_from_next(match.loser_next_match, match.loser_next_match_slot)