saving issue fixed

This commit is contained in:
bl3kunja-FW
2025-11-11 17:34:42 +01:00
parent 23dc5673ee
commit fd44ca7128
4 changed files with 58 additions and 24 deletions
+8 -6
View File
@@ -171,7 +171,7 @@ class ArchiveStorage(FileStorage):
@staticmethod @staticmethod
def archive_tournament(tournament_data, results_data): def archive_tournament(tournament_data, results_data):
"""Archive completed tournament data""" """Archive completed tournament data. Returns (success, filename) tuple"""
try: try:
FileStorage._ensure_directory(ARCHIVE_DIR) FileStorage._ensure_directory(ARCHIVE_DIR)
@@ -188,14 +188,15 @@ class ArchiveStorage(FileStorage):
success = FileStorage._write_json(archive_path, archive_data) success = FileStorage._write_json(archive_path, archive_data)
if success: if success:
print(f"Tournament archived to: {archive_path}") print(f"Tournament archived to: {archive_path}")
return success return (True, archive_filename)
return (False, None)
except Exception as e: except Exception as e:
print(f"Error archiving tournament: {e}") print(f"Error archiving tournament: {e}")
return False return (False, None)
@staticmethod @staticmethod
def archive_league(league_data): def archive_league(league_data):
"""Archive completed league data""" """Archive completed league data. Returns (success, filename) tuple"""
try: try:
FileStorage._ensure_directory(LEAGUE_ARCHIVE_DIR) FileStorage._ensure_directory(LEAGUE_ARCHIVE_DIR)
@@ -211,10 +212,11 @@ class ArchiveStorage(FileStorage):
success = FileStorage._write_json(archive_path, archive_data) success = FileStorage._write_json(archive_path, archive_data)
if success: if success:
print(f"League archived to: {archive_path}") print(f"League archived to: {archive_path}")
return success return (True, archive_filename)
return (False, None)
except Exception as e: except Exception as e:
print(f"Error archiving league: {e}") print(f"Error archiving league: {e}")
return False return (False, None)
@staticmethod @staticmethod
def get_archived_tournaments(): def get_archived_tournaments():
+18 -2
View File
@@ -1305,10 +1305,26 @@
if (response.ok) { if (response.ok) {
const responseData = await response.json(); 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...'); alert('Tournament finished successfully! Showing results...');
setTimeout(() => { setTimeout(() => {
window.location.href = '/results'; window.location.href = redirectUrl;
}, 1000); }, 1000);
} else { } else {
const error = await response.json(); const error = await response.json();
+10 -2
View File
@@ -1505,7 +1505,7 @@
<div class="league-tournament-card league"> <div class="league-tournament-card league">
<h3>🏆 <span data-i18n="league.league_active">Liga (Aktivna)</span></h3> <h3>🏆 <span data-i18n="league.league_active">Liga (Aktivna)</span></h3>
<div class="unified-status league"> <div class="unified-status league">
<span data-i18n="league.league_active">Liga je Aktivna</span> - {{ league_state.completed_tournaments|length }}/{{ league_state.total_tournaments }} <span data-i18n="tournament.completed">Zaključeno</span> <span data-i18n="league.league_active">Liga je Aktivna</span>
</div> </div>
<div class="compact-info-grid"> <div class="compact-info-grid">
<div class="compact-info-item"> <div class="compact-info-item">
@@ -1533,7 +1533,7 @@
<!-- Tournament Progress Timeline --> <!-- Tournament Progress Timeline -->
<div class="rounds-progress-bar"> <div class="rounds-progress-bar">
<div class="rounds-progress-title"> <div class="rounds-progress-title">
📊 <span data-i18n="league.tournaments">Turnirji</span> - {{ league_state.completed_tournaments|length }}/{{ league_state.total_tournaments }} 📊 <span data-i18n="league.tournaments">Turnirji</span>
</div> </div>
<div class="rounds-progress-horizontal"> <div class="rounds-progress-horizontal">
{% for i in range(1, league_state.total_tournaments + 1) %} {% for i in range(1, league_state.total_tournaments + 1) %}
@@ -2650,6 +2650,14 @@
console.log('🏆 Tournament Management loaded'); console.log('🏆 Tournament Management loaded');
console.log('League active:', leagueActive); console.log('League active:', leagueActive);
console.log('Tournament active:', tournamentActive); console.log('Tournament active:', tournamentActive);
{% if league_state %}
console.log('📊 League State Debug:');
console.log(' - Completed tournaments:', {{ league_state.completed_tournaments|length }});
console.log(' - Total tournaments:', {{ league_state.total_tournaments }});
console.log(' - Current tournament:', {{ league_state.current_tournament }});
console.log(' - Completed list:', {{ league_state.completed_tournaments|tojson }});
{% endif %}
}, { once: true }); }, { once: true });
}); });
</script> </script>
+14 -6
View File
@@ -1286,7 +1286,7 @@ def reset_league():
# Archive current league if it exists # Archive current league if it exists
league_state = load_league_state() league_state = load_league_state()
if league_state: if league_state:
archive_league(league_state) _, _ = archive_league(league_state) # Unpack tuple but ignore values
# Remove league, tournament, and results files # Remove league, tournament, and results files
for file_path in [LEAGUE_FILE, TOURNAMENT_FILE, RESULTS_FILE]: for file_path in [LEAGUE_FILE, TOURNAMENT_FILE, RESULTS_FILE]:
@@ -1526,8 +1526,9 @@ def finish_tournament():
# Archive the tournament (only if it's NOT part of a league) # Archive the tournament (only if it's NOT part of a league)
archive_success = False archive_success = False
archive_filename = None
if not league_state: # Only archive standalone tournaments if not league_state: # Only archive standalone tournaments
archive_success = archive_tournament(tournament_state, results) archive_success, archive_filename = archive_tournament(tournament_state, results)
tournament_type = results.get('tournament_type', '20_targets') tournament_type = results.get('tournament_type', '20_targets')
print(f"Standalone {tournament_type} tournament archived: {archive_success}") print(f"Standalone {tournament_type} tournament archived: {archive_success}")
else: else:
@@ -1536,8 +1537,9 @@ def finish_tournament():
# Archive the league if it just finished # Archive the league if it just finished
league_archive_success = False league_archive_success = False
league_archive_filename = None
if league_finished and league_state: if league_finished and league_state:
league_archive_success = archive_league(league_state) league_archive_success, league_archive_filename = archive_league(league_state)
print(f"League archived: {league_archive_success}") print(f"League archived: {league_archive_success}")
# Save final results # Save final results
@@ -1550,15 +1552,21 @@ def finish_tournament():
if league_finished and os.path.exists(LEAGUE_FILE): if league_finished and os.path.exists(LEAGUE_FILE):
os.remove(LEAGUE_FILE) os.remove(LEAGUE_FILE)
# Delete results file after archiving # Delete results file only if tournament was archived
# For non-final league tournaments, keep results file so /results route can show both league standings and tournament results
if archive_success or league_archive_success:
# Tournament or league was archived, safe to delete results
if os.path.exists(RESULTS_FILE): if os.path.exists(RESULTS_FILE):
os.remove(RESULTS_FILE) os.remove(RESULTS_FILE)
# If not archived (non-final league tournament), keep results file for display
response_data = { response_data = {
'status': 'success', 'status': 'success',
'results': results, 'results': results,
'archived': archive_success, 'archived': archive_success,
'archive_filename': archive_filename,
'league_archived': league_archive_success if league_finished else None, 'league_archived': league_archive_success if league_finished else None,
'league_archive_filename': league_archive_filename if league_finished else None,
'tournament_type': results.get('tournament_type', '20_targets'), 'tournament_type': results.get('tournament_type', '20_targets'),
'tournament_format': get_tournament_format_description(results.get('tournament_type', '20_targets')) 'tournament_format': get_tournament_format_description(results.get('tournament_type', '20_targets'))
} }
@@ -1685,10 +1693,10 @@ def emergency_reset():
results = load_results() results = load_results()
if tournament_state and results: if tournament_state and results:
archive_tournament(tournament_state, results) _, _ = archive_tournament(tournament_state, results) # Unpack tuple but ignore values
if league_state: if league_state:
archive_league(league_state) _, _ = archive_league(league_state) # Unpack tuple but ignore values
# Remove all state files # Remove all state files
for file_path in [LEAGUE_FILE, TOURNAMENT_FILE, RESULTS_FILE]: for file_path in [LEAGUE_FILE, TOURNAMENT_FILE, RESULTS_FILE]: