changes
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
# plugins/plant/routes.py
|
||||
|
||||
from uuid import uuid4
|
||||
from flask import (
|
||||
Blueprint,
|
||||
@ -12,7 +14,12 @@ from app import db
|
||||
from .models import Plant, PlantCommonName, PlantScientificName
|
||||
from .forms import PlantForm
|
||||
from plugins.media.models import Media
|
||||
from plugins.media.utils import save_media_file, delete_media_file, rotate_media_file, generate_image_url
|
||||
from plugins.media.utils import (
|
||||
save_media_file,
|
||||
delete_media_file,
|
||||
rotate_media_file,
|
||||
generate_image_url
|
||||
)
|
||||
|
||||
bp = Blueprint(
|
||||
'plant',
|
||||
@ -21,9 +28,7 @@ bp = Blueprint(
|
||||
template_folder='templates'
|
||||
)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Make generate_image_url available in all templates
|
||||
# -----------------------------------------------------------------------------
|
||||
# Make generate_image_url available in all plant templates
|
||||
@bp.app_context_processor
|
||||
def inject_image_helper():
|
||||
return dict(generate_image_url=generate_image_url)
|
||||
@ -85,7 +90,8 @@ def create():
|
||||
if form.mother_uuid.data != 'N/A'
|
||||
else None
|
||||
),
|
||||
custom_slug=form.custom_slug.data,
|
||||
# ← HERE: convert blank slug to NULL
|
||||
custom_slug=(form.custom_slug.data.strip() or None),
|
||||
notes=form.notes.data,
|
||||
data_verified=form.data_verified.data,
|
||||
is_active=form.is_active.data,
|
||||
@ -101,16 +107,17 @@ def create():
|
||||
@bp.route('/<uuid:uuid_val>', methods=['GET'])
|
||||
@login_required
|
||||
def detail(uuid_val):
|
||||
plant = Plant.query.filter_by(uuid=str(uuid_val)).first_or_404()
|
||||
plant = Plant.query.filter_by(uuid=uuid_val).first_or_404()
|
||||
return render_template('plant/detail.html', plant=plant)
|
||||
|
||||
# ─── EDIT ─────────────────────────────────────────────────────────────────────
|
||||
@bp.route('/<uuid:uuid_val>/edit', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def edit(uuid_val):
|
||||
plant = Plant.query.filter_by(uuid=str(uuid_val)).first_or_404()
|
||||
plant = Plant.query.filter_by(uuid=uuid_val).first_or_404()
|
||||
form = PlantForm()
|
||||
|
||||
# Populate dropdowns (same as in create)
|
||||
form.plant_type.choices = [
|
||||
('plant', 'Plant'),
|
||||
('cutting', 'Cutting'),
|
||||
@ -136,7 +143,7 @@ def edit(uuid_val):
|
||||
form.common_name.data = plant.common_id
|
||||
form.scientific_name.data = plant.scientific_id
|
||||
form.mother_uuid.data = plant.mother_uuid or 'N/A'
|
||||
form.custom_slug.data = plant.custom_slug
|
||||
form.custom_slug.data = plant.custom_slug or ''
|
||||
form.notes.data = plant.notes
|
||||
form.data_verified.data = plant.data_verified
|
||||
form.is_active.data = getattr(plant, 'is_active', True)
|
||||
@ -150,7 +157,8 @@ def edit(uuid_val):
|
||||
if form.mother_uuid.data != 'N/A'
|
||||
else None
|
||||
)
|
||||
plant.custom_slug = form.custom_slug.data
|
||||
# ← HERE as well
|
||||
plant.custom_slug = (form.custom_slug.data.strip() or None)
|
||||
plant.notes = form.notes.data
|
||||
plant.data_verified = form.data_verified.data
|
||||
plant.is_active = form.is_active.data
|
||||
|
Reference in New Issue
Block a user