feat: add booth open/closed toggle on settings page

This commit is contained in:
Troll (Hermes Agent) 2026-08-02 18:17:59 +00:00
parent c39265ab42
commit 5e26650b90
6 changed files with 96 additions and 6 deletions

26
app.py
View file

@ -308,6 +308,12 @@ def build_signature_images():
return [(str(logo_path), 'dm-logo')]
def get_booth_open():
"""Return True if the booth is currently marked as open in runtime settings."""
cfg = load_booth_settings()
return cfg.get('booth_open', True)
# ---------------------------------------------------------------------------
# Public customer routes
# ---------------------------------------------------------------------------
@ -323,11 +329,14 @@ def index():
def request_form():
"""
Public request form.
GET -> shows the form with the banner image.
GET -> shows the form with the banner image, or a closed message if the booth is closed.
POST -> validates the email, creates a database record, sends a
confirmation email, and redirects to the thanks page.
Rate limited to 5 submissions per minute per IP.
"""
if not get_booth_open():
return render_template('closed.html')
if request.method == 'POST':
form_data = {
'name': request.form.get('name', '').strip(),
@ -694,9 +703,9 @@ def admin_settings():
"""
Settings / maintenance page for operators.
GET -> show database health, statistics, disk usage, runtime settings forms,
SMTP/email config, MP3 metadata defaults, backup/restore, and reset.
booth open/closed switch, SMTP/email config, MP3 metadata defaults, backup/restore, and reset.
POST -> handle one of: fix_db, reset_system, save_max_revisions, save_metadata,
save_email_config, send_test_email, save_refresh, download_db, restore_db.
save_email_config, send_test_email, save_refresh, save_booth_open, download_db, restore_db.
"""
redir = require_admin()
if redir:
@ -717,6 +726,7 @@ def admin_settings():
runtime_settings = load_booth_settings()
current_max_revisions = runtime_settings.get('max_revisions', current_app.config.get('MAX_REVISIONS', 2))
current_refresh_seconds = runtime_settings.get('refresh_seconds', 10)
booth_open = runtime_settings.get('booth_open', True)
# Effective email config to show in the form (non-sensitive only; password left blank).
email_form = {
@ -868,6 +878,15 @@ def admin_settings():
flash(f'Dashboard auto-refresh set to {val} seconds.', 'success')
return redirect(url_for('admin_settings'))
elif action == 'save_booth_open':
# Toggle whether the public request form is accepting submissions.
cfg = load_booth_settings()
cfg['booth_open'] = request.form.get('booth_open', '1') == '1'
save_booth_settings(cfg)
state = 'open' if cfg['booth_open'] else 'closed'
flash(f'Booth is now {state}.', 'success')
return redirect(url_for('admin_settings'))
elif action == 'download_db':
# Send the SQLite database file as a download.
if db_path.exists():
@ -915,6 +934,7 @@ def admin_settings():
upload_path=str(upload_root),
current_max_revisions=current_max_revisions,
current_refresh_seconds=current_refresh_seconds,
booth_open=booth_open,
email_form=email_form,
metadata=runtime_settings,
)