fix: keep metadata and email fields populated after saving settings

This commit is contained in:
Troll (Hermes Agent) 2026-08-02 18:05:51 +00:00
parent 35c8a722fe
commit c39265ab42

24
app.py
View file

@ -217,7 +217,13 @@ def load_booth_settings():
cfg_path = settings_file_path() cfg_path = settings_file_path()
if cfg_path.exists(): if cfg_path.exists():
try: try:
return json.loads(cfg_path.read_text()) cfg = json.loads(cfg_path.read_text())
# Normalize any legacy None metadata/email values to empty strings
# so form fields repopulate correctly after reload.
for key in ('artist', 'album', 'year', 'comment', 'smtp_host', 'smtp_port', 'smtp_user', 'smtp_from'):
if cfg.get(key) is None:
cfg[key] = ''
return cfg
except (json.JSONDecodeError, OSError): except (json.JSONDecodeError, OSError):
pass pass
return {} return {}
@ -813,22 +819,22 @@ def admin_settings():
elif action == 'save_metadata': elif action == 'save_metadata':
# Update MP3 metadata defaults from the settings form. # Update MP3 metadata defaults from the settings form.
# Store empty strings (not None) so fields repopulate correctly on reload.
cfg = load_booth_settings() cfg = load_booth_settings()
cfg['artist'] = request.form.get('artist', '').strip() or None for key in ('artist', 'album', 'year', 'comment'):
cfg['album'] = request.form.get('album', '').strip() or None cfg[key] = request.form.get(key, '').strip()
cfg['year'] = request.form.get('year', '').strip() or None
cfg['comment'] = request.form.get('comment', '').strip() or None
save_booth_settings(cfg) save_booth_settings(cfg)
flash('MP3 metadata defaults saved.', 'success') flash('MP3 metadata defaults saved.', 'success')
return redirect(url_for('admin_settings')) return redirect(url_for('admin_settings'))
elif action == 'save_email_config': elif action == 'save_email_config':
# Update SMTP settings from the settings form. Password is encrypted. # Update SMTP settings from the settings form. Password is encrypted.
# Empty values are stored as empty strings so the form repopulates.
cfg = load_booth_settings() cfg = load_booth_settings()
cfg['smtp_host'] = request.form.get('smtp_host', '').strip() or None cfg['smtp_host'] = request.form.get('smtp_host', '').strip()
cfg['smtp_port'] = request.form.get('smtp_port', '').strip() or None cfg['smtp_port'] = request.form.get('smtp_port', '').strip()
cfg['smtp_user'] = request.form.get('smtp_user', '').strip() or None cfg['smtp_user'] = request.form.get('smtp_user', '').strip()
cfg['smtp_from'] = request.form.get('smtp_from', '').strip() or None cfg['smtp_from'] = request.form.get('smtp_from', '').strip()
new_pass = request.form.get('smtp_pass', '').strip() new_pass = request.form.get('smtp_pass', '').strip()
# Only overwrite the stored password if a new value was provided. # Only overwrite the stored password if a new value was provided.
if new_pass: if new_pass: