fix: keep metadata and email fields populated after saving settings
This commit is contained in:
parent
35c8a722fe
commit
c39265ab42
1 changed files with 15 additions and 9 deletions
24
app.py
24
app.py
|
|
@ -217,7 +217,13 @@ def load_booth_settings():
|
|||
cfg_path = settings_file_path()
|
||||
if cfg_path.exists():
|
||||
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):
|
||||
pass
|
||||
return {}
|
||||
|
|
@ -813,22 +819,22 @@ def admin_settings():
|
|||
|
||||
elif action == 'save_metadata':
|
||||
# Update MP3 metadata defaults from the settings form.
|
||||
# Store empty strings (not None) so fields repopulate correctly on reload.
|
||||
cfg = load_booth_settings()
|
||||
cfg['artist'] = request.form.get('artist', '').strip() or None
|
||||
cfg['album'] = request.form.get('album', '').strip() or None
|
||||
cfg['year'] = request.form.get('year', '').strip() or None
|
||||
cfg['comment'] = request.form.get('comment', '').strip() or None
|
||||
for key in ('artist', 'album', 'year', 'comment'):
|
||||
cfg[key] = request.form.get(key, '').strip()
|
||||
save_booth_settings(cfg)
|
||||
flash('MP3 metadata defaults saved.', 'success')
|
||||
return redirect(url_for('admin_settings'))
|
||||
|
||||
elif action == 'save_email_config':
|
||||
# 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['smtp_host'] = request.form.get('smtp_host', '').strip() or None
|
||||
cfg['smtp_port'] = request.form.get('smtp_port', '').strip() or None
|
||||
cfg['smtp_user'] = request.form.get('smtp_user', '').strip() or None
|
||||
cfg['smtp_from'] = request.form.get('smtp_from', '').strip() or None
|
||||
cfg['smtp_host'] = request.form.get('smtp_host', '').strip()
|
||||
cfg['smtp_port'] = request.form.get('smtp_port', '').strip()
|
||||
cfg['smtp_user'] = request.form.get('smtp_user', '').strip()
|
||||
cfg['smtp_from'] = request.form.get('smtp_from', '').strip()
|
||||
new_pass = request.form.get('smtp_pass', '').strip()
|
||||
# Only overwrite the stored password if a new value was provided.
|
||||
if new_pass:
|
||||
|
|
|
|||
Reference in a new issue