Add admin Pricing page with fixed and custom items
This commit is contained in:
parent
a3fd5938a5
commit
a25bf3a9c9
3 changed files with 156 additions and 1 deletions
46
app.py
46
app.py
|
|
@ -801,6 +801,52 @@ def admin_sales():
|
|||
return render_template('admin/sales.html', sales=sales, statuses=STATUS_LABELS)
|
||||
|
||||
|
||||
@app.route('/admin/pricing', methods=['GET', 'POST'])
|
||||
def admin_pricing():
|
||||
"""
|
||||
Pricing configuration page.
|
||||
Fixed items: one_song, both_songs, wav_per_song, stems_per_song.
|
||||
Plus up to 5 custom name/price pairs.
|
||||
"""
|
||||
redir = require_admin()
|
||||
if redir:
|
||||
return redir
|
||||
|
||||
fixed_keys = ['one_song', 'both_songs', 'wav_per_song', 'stems_per_song']
|
||||
custom_count = 5
|
||||
|
||||
cfg = load_booth_settings()
|
||||
if 'pricing' not in cfg:
|
||||
cfg['pricing'] = {}
|
||||
|
||||
if request.method == 'POST':
|
||||
pricing = {}
|
||||
for key in fixed_keys:
|
||||
pricing[key] = request.form.get(key, '').strip()
|
||||
for i in range(1, custom_count + 1):
|
||||
name = request.form.get(f'custom_name_{i}', '').strip()
|
||||
price = request.form.get(f'custom_price_{i}', '').strip()
|
||||
if name:
|
||||
pricing[f'custom_{i}'] = {'name': name, 'price': price}
|
||||
else:
|
||||
pricing[f'custom_{i}'] = None
|
||||
cfg['pricing'] = pricing
|
||||
save_booth_settings(cfg)
|
||||
flash('Pricing saved.', 'success')
|
||||
return redirect(url_for('admin_pricing'))
|
||||
|
||||
pricing = cfg.get('pricing', {})
|
||||
fixed = {key: pricing.get(key, '') for key in fixed_keys}
|
||||
customs = []
|
||||
for i in range(1, custom_count + 1):
|
||||
entry = pricing.get(f'custom_{i}')
|
||||
customs.append({
|
||||
'name': entry.get('name', '') if isinstance(entry, dict) else '',
|
||||
'price': entry.get('price', '') if isinstance(entry, dict) else ''
|
||||
})
|
||||
return render_template('admin/pricing.html', fixed=fixed, customs=customs)
|
||||
|
||||
|
||||
@app.route('/admin/request/<int:rid>', methods=['GET', 'POST'])
|
||||
def admin_request(rid):
|
||||
"""
|
||||
|
|
|
|||
Reference in a new issue