Removed some ghost bracket, hidden rest match and better rendering and score submitting

This commit is contained in:
2026-02-23 01:04:27 +01:00 Verified
parent b152f6fd85
commit 0b3f857f50
5 changed files with 91 additions and 61 deletions
+22 -4
View File
@@ -4,6 +4,7 @@ from datetime import timedelta
from uuid import uuid4
from sqlalchemy.orm import Session
from sqlalchemy.orm.attributes import flag_modified
from . import models
from .constants import BracketTypes, MatchStatus, TournamentTypes
@@ -190,8 +191,11 @@ def advance_winner(db: Session, match: models.Match, winner_id: int):
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.winner_team_id = None
reset_match.sets = []
flag_modified(reset_match, "sets")
reset_match.p1_team_id = None
reset_match.p2_team_id = None
reset_match.status = MatchStatus.SCHEDULED
@@ -205,6 +209,18 @@ def advance_winner(db: Session, match: models.Match, winner_id: int):
):
if not next_match or target_slot is None:
return
current_team = (
next_match.p1_team_id if target_slot == 0 else next_match.p2_team_id
)
if current_team and current_team != team_id:
if next_match.winner_team_id:
undo_advancement(db, next_match)
next_match.winner_team_id = None
next_match.sets = []
flag_modified(next_match, "sets")
next_match.status = MatchStatus.SCHEDULED
if target_slot == 0:
next_match.p1_team_id = team_id
elif target_slot == 1:
@@ -239,8 +255,10 @@ def undo_advancement(db: Session, match: models.Match):
if next_match.winner_team_id:
undo_advancement(db, next_match)
next_match.winner_team_id = None
next_match.sets = []
next_match.winner_team_id = None
next_match.sets = []
flag_modified(next_match, "sets")
if target_slot == 0:
next_match.p1_team_id = None
+11 -3
View File
@@ -42,13 +42,17 @@ async def report_score(
if not report.sets:
raise HTTPException(400, "No sets submitted")
if match.winner_team_id:
logic.undo_advancement(db, match)
_apply_score(match, report.sets)
flag_modified(match, "sets")
db.commit()
if match.winner_team_id:
logic.advance_winner(db, match, match.winner_team_id)
db.commit()
await send_ws_update(id)
return SUCCESS
@@ -77,11 +81,12 @@ async def edit_score(
_apply_score(match, report.sets)
flag_modified(match, "sets")
db.commit()
if match.winner_team_id:
logic.advance_winner(db, match, match.winner_team_id)
db.commit()
await send_ws_update(id)
return SUCCESS
@@ -107,7 +112,10 @@ async def clear_score(
logic.undo_advancement(db, match)
match.winner_team_id = None
match.status = MatchStatus.PENDING
if match.p1_team_id and match.p2_team_id:
match.status = MatchStatus.PENDING
else:
match.status = MatchStatus.SCHEDULED
match.sets = []
flag_modified(match, "sets")