diff --git a/app/storage.py b/app/storage.py index 0755a8d..f129250 100644 --- a/app/storage.py +++ b/app/storage.py @@ -171,7 +171,7 @@ class ArchiveStorage(FileStorage): @staticmethod def archive_tournament(tournament_data, results_data): - """Archive completed tournament data""" + """Archive completed tournament data. Returns (success, filename) tuple""" try: FileStorage._ensure_directory(ARCHIVE_DIR) @@ -188,14 +188,15 @@ class ArchiveStorage(FileStorage): success = FileStorage._write_json(archive_path, archive_data) if success: print(f"Tournament archived to: {archive_path}") - return success + return (True, archive_filename) + return (False, None) except Exception as e: print(f"Error archiving tournament: {e}") - return False + return (False, None) @staticmethod def archive_league(league_data): - """Archive completed league data""" + """Archive completed league data. Returns (success, filename) tuple""" try: FileStorage._ensure_directory(LEAGUE_ARCHIVE_DIR) @@ -211,10 +212,11 @@ class ArchiveStorage(FileStorage): success = FileStorage._write_json(archive_path, archive_data) if success: print(f"League archived to: {archive_path}") - return success + return (True, archive_filename) + return (False, None) except Exception as e: print(f"Error archiving league: {e}") - return False + return (False, None) @staticmethod def get_archived_tournaments(): diff --git a/templates/results_calculator.html b/templates/results_calculator.html index 147ad79..e69c238 100644 --- a/templates/results_calculator.html +++ b/templates/results_calculator.html @@ -1305,10 +1305,26 @@ if (response.ok) { const responseData = await response.json(); - // Always show results first when tournament finishes + // Determine where to redirect based on tournament type and archive + let redirectUrl = '/results'; + + // Priority 1: If league finished, redirect to league archive + if (responseData.league_archived && responseData.league_archive_filename) { + redirectUrl = `/archive/league/${responseData.league_archive_filename}`; + } + // Priority 2: If standalone tournament, redirect to tournament archive + else if (responseData.archived && responseData.archive_filename) { + redirectUrl = `/archive/tournament/${responseData.archive_filename}`; + } + // Priority 3: If league tournament (not final), show league standings + else if (responseData.league && !responseData.league_finished) { + redirectUrl = '/results'; // This will show league standings with current tournament + } + + // Always show results after tournament finishes alert('Tournament finished successfully! Showing results...'); setTimeout(() => { - window.location.href = '/results'; + window.location.href = redirectUrl; }, 1000); } else { const error = await response.json(); diff --git a/templates/tournament.html b/templates/tournament.html index c386dba..bb37e76 100644 --- a/templates/tournament.html +++ b/templates/tournament.html @@ -1505,7 +1505,7 @@