From c39265ab422c42836b8dc1971c654d8b3dfae93b Mon Sep 17 00:00:00 2001 From: "Troll (Hermes Agent)" Date: Sun, 2 Aug 2026 18:05:51 +0000 Subject: [PATCH] fix: keep metadata and email fields populated after saving settings --- app.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 3f1bfec..5377977 100644 --- a/app.py +++ b/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: