stuff is working again
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
# plugins/media/routes.py
|
||||
|
||||
import os
|
||||
import uuid
|
||||
import io
|
||||
@ -19,7 +17,6 @@ from PIL import Image, ExifTags
|
||||
|
||||
from app import db
|
||||
from .models import Media, ImageHeart, FeaturedImage
|
||||
from plugins.plant.models import Plant
|
||||
|
||||
bp = Blueprint(
|
||||
"media",
|
||||
@ -306,35 +303,41 @@ def set_featured_image(context, context_id, media_id):
|
||||
"""
|
||||
Single‐select “featured” toggle for any plugin (plants, grow_logs, etc).
|
||||
"""
|
||||
# normalize to plural
|
||||
plugin_ctx = context if context.endswith('s') else context + 's'
|
||||
if plugin_ctx not in ('plants', 'grow_logs', 'users', 'vendors'):
|
||||
# normalize to singular plugin name (matches Media.plugin & FeaturedImage.context)
|
||||
valid = {'plant', 'growlog', 'user', 'vendor'}
|
||||
if context in valid:
|
||||
plugin_name = context
|
||||
elif context.endswith('s') and context[:-1] in valid:
|
||||
plugin_name = context[:-1]
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
# must own that media row
|
||||
media = Media.query.filter_by(
|
||||
plugin=plugin_ctx,
|
||||
plugin=plugin_name,
|
||||
related_id=context_id,
|
||||
id=media_id
|
||||
).first_or_404()
|
||||
|
||||
# clear out any existing
|
||||
# clear out any existing featured rows
|
||||
FeaturedImage.query.filter_by(
|
||||
context=plugin_ctx,
|
||||
context=plugin_name,
|
||||
context_id=context_id
|
||||
).delete()
|
||||
|
||||
# insert new featured row
|
||||
fi = FeaturedImage(
|
||||
media_id=media.id,
|
||||
context=plugin_ctx,
|
||||
context=plugin_name,
|
||||
context_id=context_id,
|
||||
is_featured=True
|
||||
)
|
||||
db.session.add(fi)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({"media_id": media.id})
|
||||
# Redirect back with a flash instead of JSON
|
||||
flash("Featured image updated.", "success")
|
||||
return redirect(request.referrer or url_for("core_ui.home"))
|
||||
|
||||
|
||||
@bp.route("/delete/<int:media_id>", methods=["POST"])
|
||||
|
Reference in New Issue
Block a user