saving issue fixed
This commit is contained in:
+8
-6
@@ -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():
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1505,7 +1505,7 @@
|
||||
<div class="league-tournament-card league">
|
||||
<h3>🏆 <span data-i18n="league.league_active">Liga (Aktivna)</span></h3>
|
||||
<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 class="compact-info-grid">
|
||||
<div class="compact-info-item">
|
||||
@@ -1533,7 +1533,7 @@
|
||||
<!-- Tournament Progress Timeline -->
|
||||
<div class="rounds-progress-bar">
|
||||
<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 class="rounds-progress-horizontal">
|
||||
{% for i in range(1, league_state.total_tournaments + 1) %}
|
||||
@@ -2650,6 +2650,14 @@
|
||||
console.log('🏆 Tournament Management loaded');
|
||||
console.log('League active:', leagueActive);
|
||||
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 });
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1286,7 +1286,7 @@ def reset_league():
|
||||
# Archive current league if it exists
|
||||
league_state = load_league_state()
|
||||
if league_state:
|
||||
archive_league(league_state)
|
||||
_, _ = archive_league(league_state) # Unpack tuple but ignore values
|
||||
|
||||
# Remove league, tournament, and results files
|
||||
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_success = False
|
||||
archive_filename = None
|
||||
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')
|
||||
print(f"Standalone {tournament_type} tournament archived: {archive_success}")
|
||||
else:
|
||||
@@ -1536,8 +1537,9 @@ def finish_tournament():
|
||||
|
||||
# Archive the league if it just finished
|
||||
league_archive_success = False
|
||||
league_archive_filename = None
|
||||
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}")
|
||||
|
||||
# Save final results
|
||||
@@ -1550,15 +1552,21 @@ def finish_tournament():
|
||||
if league_finished and os.path.exists(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):
|
||||
os.remove(RESULTS_FILE)
|
||||
# If not archived (non-final league tournament), keep results file for display
|
||||
|
||||
response_data = {
|
||||
'status': 'success',
|
||||
'results': results,
|
||||
'archived': archive_success,
|
||||
'archive_filename': archive_filename,
|
||||
'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_format': get_tournament_format_description(results.get('tournament_type', '20_targets'))
|
||||
}
|
||||
@@ -1685,10 +1693,10 @@ def emergency_reset():
|
||||
results = load_results()
|
||||
|
||||
if tournament_state and results:
|
||||
archive_tournament(tournament_state, results)
|
||||
_, _ = archive_tournament(tournament_state, results) # Unpack tuple but ignore values
|
||||
|
||||
if league_state:
|
||||
archive_league(league_state)
|
||||
_, _ = archive_league(league_state) # Unpack tuple but ignore values
|
||||
|
||||
# Remove all state files
|
||||
for file_path in [LEAGUE_FILE, TOURNAMENT_FILE, RESULTS_FILE]:
|
||||
|
||||
Reference in New Issue
Block a user