Enable editing of competition details and images in the admin panel
Adds a new POST route `/admin/competition/edit` to update competition data in the database, including handling image uploads and preserving existing images. Updates `replit.md` and `templates/admin/competitions.html` to include UI elements and logic for editing competitions. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cd9a7d26-a4e5-4215-975c-c59f4ed1f06d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 5f81296b-a857-4536-9a1e-2ccf05671a10 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/d0a1d46d-d203-4308-bc6a-312ac7c0243b/cd9a7d26-a4e5-4215-975c-c59f4ed1f06d/EU15Bjz
This commit is contained in:
40
app.py
40
app.py
@@ -278,6 +278,46 @@ def add_competition():
|
||||
flash('Competition added successfully', 'success')
|
||||
return redirect(url_for('admin_competitions'))
|
||||
|
||||
@app.route('/admin/competition/edit', methods=['POST'])
|
||||
@admin_required
|
||||
def edit_competition():
|
||||
competition_id = request.form.get('id')
|
||||
season = request.form.get('season')
|
||||
event_name = request.form.get('event_name')
|
||||
date = request.form.get('date')
|
||||
description = request.form.get('description')
|
||||
awards_raw = request.form.get('awards')
|
||||
awards = '|'.join([line.strip() for line in awards_raw.split('\n') if line.strip()]) if awards_raw else ''
|
||||
|
||||
conn = get_db_connection()
|
||||
cur = conn.cursor(cursor_factory=RealDictCursor)
|
||||
|
||||
# Get current competition to check for existing image
|
||||
cur.execute('SELECT image_path FROM competitions WHERE id = %s', (competition_id,))
|
||||
current_comp = cur.fetchone()
|
||||
image_path = current_comp['image_path'] if current_comp else None
|
||||
|
||||
# Handle new image upload
|
||||
if 'image' in request.files:
|
||||
file = request.files['image']
|
||||
if file and file.filename:
|
||||
filename = secure_filename(file.filename)
|
||||
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||
image_path = f'images/{filename}'
|
||||
|
||||
# Update competition
|
||||
cur.execute('''UPDATE competitions
|
||||
SET season = %s, event_name = %s, date = %s,
|
||||
description = %s, awards = %s, image_path = %s
|
||||
WHERE id = %s''',
|
||||
(season, event_name, date, description, awards, image_path, competition_id))
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
flash('Competition updated successfully', 'success')
|
||||
return redirect(url_for('admin_competitions'))
|
||||
|
||||
@app.route('/admin/competition/delete', methods=['POST'])
|
||||
@admin_required
|
||||
def delete_competition():
|
||||
|
||||
Reference in New Issue
Block a user