saving issue fixed
This commit is contained in:
+8
-6
@@ -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():
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -1286,13 +1286,13 @@ 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]:
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
|
|
||||||
return jsonify({'status': 'success'})
|
return jsonify({'status': 'success'})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'status': 'error', 'message': str(e)}), 400
|
return jsonify({'status': 'error', 'message': str(e)}), 400
|
||||||
@@ -1526,20 +1526,22 @@ 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:
|
||||||
tournament_type = results.get('tournament_type', '20_targets')
|
tournament_type = results.get('tournament_type', '20_targets')
|
||||||
print(f"League {tournament_type} tournament - not archiving individual tournament")
|
print(f"League {tournament_type} tournament - not archiving individual 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
|
||||||
if save_results(results):
|
if save_results(results):
|
||||||
# End the tournament by removing tournament state
|
# End the tournament by removing tournament state
|
||||||
@@ -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
|
||||||
if os.path.exists(RESULTS_FILE):
|
# For non-final league tournaments, keep results file so /results route can show both league standings and tournament results
|
||||||
os.remove(RESULTS_FILE)
|
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 = {
|
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'))
|
||||||
}
|
}
|
||||||
@@ -1683,12 +1691,12 @@ def emergency_reset():
|
|||||||
tournament_state = load_tournament_state()
|
tournament_state = load_tournament_state()
|
||||||
league_state = load_league_state()
|
league_state = load_league_state()
|
||||||
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]:
|
||||||
|
|||||||
Reference in New Issue
Block a user