From 823a96275a5f4c3fc3d81f709de5ec44ffa9e292 Mon Sep 17 00:00:00 2001 From: abhiramtx <7253115-abhiramtx@users.noreply.replit.com> Date: Wed, 12 Nov 2025 16:17:31 +0000 Subject: [PATCH] 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 --- .replit | 4 ++ app.py | 40 +++++++++++++++ replit.md | 18 +++++++ templates/admin/competitions.html | 81 +++++++++++++++++++++++++++++-- 4 files changed, 139 insertions(+), 4 deletions(-) diff --git a/.replit b/.replit index ecbc26d..718d5f0 100644 --- a/.replit +++ b/.replit @@ -12,6 +12,10 @@ deploymentTarget = "cloudrun" localPort = 5000 externalPort = 80 +[[ports]] +localPort = 33703 +externalPort = 3001 + [[ports]] localPort = 37833 externalPort = 3000 diff --git a/app.py b/app.py index 55d3b4d..aceb5dd 100644 --- a/app.py +++ b/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(): diff --git a/replit.md b/replit.md index c8d0e71..7b5deae 100644 --- a/replit.md +++ b/replit.md @@ -3,6 +3,24 @@ ## Overview Flask-based website for FTC Team 23344 with a modern dark theme (#000000 pure black background), comprehensive content management system, PostgreSQL database integration, and premium smooth-scrolling animations. +## Recent Changes (November 12, 2025) + +### Admin Panel Enhancement: Competition Editing +Added full CRUD functionality to the competitions admin panel: + +**New Features:** +- ✏️ **Edit Competition Cards**: Click the "Edit" button on any competition to modify its details +- **Collapsible Edit Forms**: Each competition now has an inline edit form that expands/collapses +- **Full Field Editing**: Edit season, event name, date, description, awards, and replace images +- **Image Preservation**: Existing images are preserved unless a new one is uploaded +- **Yellow Edit Buttons**: New amber/yellow themed edit buttons next to delete buttons + +**Technical Implementation:** +- New `/admin/competition/edit` route in Flask backend +- Inline collapsible forms with JavaScript toggle functionality +- Award text automatically converted between pipe-separated (database) and newline-separated (form) formats +- Retains existing image if no new file uploaded + ## Recent Changes (November 8, 2025) ### Latest UI/UX Refinements diff --git a/templates/admin/competitions.html b/templates/admin/competitions.html index e13a8cb..8305f75 100644 --- a/templates/admin/competitions.html +++ b/templates/admin/competitions.html @@ -116,12 +116,35 @@ .btn-danger:hover { background: rgba(239, 68, 68, 0.3); } + .btn-warning { + background: rgba(251, 191, 36, 0.2); + color: #fbbf24; + margin-right: 8px; + } + .btn-warning:hover { + background: rgba(251, 191, 36, 0.3); + } .info-text { color: var(--gray-400); font-family: var(--font-body); font-size: 13px; margin-top: 4px; } + .edit-form { + display: none; + background: #0d0d0d; + border: 1px solid #444; + border-radius: 12px; + padding: 20px; + margin-top: 16px; + } + .edit-form.active { + display: block; + } + .action-buttons { + display: flex; + gap: 8px; + } {% endblock %} @@ -179,17 +202,67 @@
{{ comp.description }}
{% if comp.awards %}🏆 {{ comp.awards|replace('|', ' · ') }}
{% endif %} + +