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:
4
.replit
4
.replit
@@ -12,6 +12,10 @@ deploymentTarget = "cloudrun"
|
||||
localPort = 5000
|
||||
externalPort = 80
|
||||
|
||||
[[ports]]
|
||||
localPort = 33703
|
||||
externalPort = 3001
|
||||
|
||||
[[ports]]
|
||||
localPort = 37833
|
||||
externalPort = 3000
|
||||
|
||||
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():
|
||||
|
||||
18
replit.md
18
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
@@ -179,17 +202,67 @@
|
||||
<h3 class="comp-title">{{ comp.event_name }}</h3>
|
||||
<p class="comp-meta">{{ comp.season }} · {{ comp.date }}</p>
|
||||
</div>
|
||||
<form method="POST" action="{{ url_for('delete_competition') }}">
|
||||
<input type="hidden" name="id" value="{{ comp.id }}">
|
||||
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure?')">Delete</button>
|
||||
</form>
|
||||
<div class="action-buttons">
|
||||
<button type="button" class="btn btn-warning" onclick="toggleEdit({{ comp.id }})">Edit</button>
|
||||
<form method="POST" action="{{ url_for('delete_competition') }}" style="display: inline;">
|
||||
<input type="hidden" name="id" value="{{ comp.id }}">
|
||||
<button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure?')">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<p class="comp-description">{{ comp.description }}</p>
|
||||
{% if comp.awards %}
|
||||
<p class="comp-awards">🏆 {{ comp.awards|replace('|', ' · ') }}</p>
|
||||
{% endif %}
|
||||
|
||||
<div id="edit-form-{{ comp.id }}" class="edit-form">
|
||||
<form method="POST" action="{{ url_for('edit_competition') }}" enctype="multipart/form-data">
|
||||
<input type="hidden" name="id" value="{{ comp.id }}">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Season</label>
|
||||
<input type="text" name="season" class="form-input" value="{{ comp.season }}" list="seasons" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Event Name</label>
|
||||
<input type="text" name="event_name" class="form-input" value="{{ comp.event_name }}" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Date</label>
|
||||
<input type="text" name="date" class="form-input" value="{{ comp.date }}" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Description</label>
|
||||
<textarea name="description" class="form-textarea" required>{{ comp.description }}</textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Awards (optional)</label>
|
||||
<textarea name="awards" class="form-textarea" placeholder="One award per line">{{ comp.awards|replace('|', '\n') if comp.awards else '' }}</textarea>
|
||||
<p class="info-text">Enter each award on a new line</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Competition Image (optional)</label>
|
||||
<input type="file" name="image" class="form-input" accept="image/*">
|
||||
{% if comp.image_path %}
|
||||
<p class="info-text">Current image: {{ comp.image_path }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="action-buttons">
|
||||
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||
<button type="button" class="btn btn-danger" onclick="toggleEdit({{ comp.id }})">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleEdit(competitionId) {
|
||||
const editForm = document.getElementById('edit-form-' + competitionId);
|
||||
editForm.classList.toggle('active');
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user