Fix TypeError when loading max_revisions from settings JSON
The customer player page (/play/<token>) and revision endpoint were reading max_revisions directly from booth_settings.json, where it is stored as a string. Arithmetic/comparison with revision_count (an int) raised TypeError and caused a 500 error when opening the customer player. Add get_max_revisions() helper that always returns a non-negative int, and use it in play(), revise(), and admin_settings().
This commit is contained in:
parent
b8ddff9afe
commit
9524a24715
1 changed files with 13 additions and 5 deletions
18
app.py
18
app.py
|
|
@ -309,6 +309,16 @@ def get_kiosk_mode():
|
|||
return 'cycle'
|
||||
|
||||
|
||||
def get_max_revisions():
|
||||
"""Return the effective max revisions as an integer."""
|
||||
cfg = load_booth_settings()
|
||||
try:
|
||||
val = int(cfg.get('max_revisions', current_app.config.get('MAX_REVISIONS', 2)))
|
||||
except (ValueError, TypeError):
|
||||
val = current_app.config.get('MAX_REVISIONS', 2)
|
||||
return max(0, val)
|
||||
|
||||
|
||||
def get_hermes_api_key():
|
||||
"""
|
||||
Return the effective Hermes API key.
|
||||
|
|
@ -606,8 +616,7 @@ def play(token):
|
|||
abort(404)
|
||||
|
||||
# Load runtime max revisions setting.
|
||||
runtime_settings = load_booth_settings()
|
||||
max_revisions = runtime_settings.get('max_revisions', current_app.config['MAX_REVISIONS'])
|
||||
max_revisions = get_max_revisions()
|
||||
revisions_left = max(0, max_revisions - (req.get('revision_count') or 0))
|
||||
|
||||
return render_template('player.html', req=req, revisions_left=revisions_left)
|
||||
|
|
@ -647,8 +656,7 @@ def revise(token):
|
|||
abort(404)
|
||||
|
||||
# Enforce max revisions limit for customer-submitted revisions.
|
||||
runtime_settings = load_booth_settings()
|
||||
max_revisions = runtime_settings.get('max_revisions', current_app.config['MAX_REVISIONS'])
|
||||
max_revisions = get_max_revisions()
|
||||
current_count = req.get('revision_count') or 0
|
||||
if current_count >= max_revisions:
|
||||
flash('Revision limit reached. Please speak to the booth operator if you need further changes.', 'error')
|
||||
|
|
@ -1151,7 +1159,7 @@ def admin_settings():
|
|||
|
||||
# Load persistent runtime settings (max_revisions overrides env var if set).
|
||||
runtime_settings = load_booth_settings()
|
||||
current_max_revisions = runtime_settings.get('max_revisions', current_app.config.get('MAX_REVISIONS', 2))
|
||||
current_max_revisions = get_max_revisions()
|
||||
current_refresh_seconds = runtime_settings.get('refresh_seconds', 10)
|
||||
booth_open = runtime_settings.get('booth_open', True)
|
||||
|
||||
|
|
|
|||
Reference in a new issue