This commit is contained in:
2025-06-11 02:47:01 -05:00
parent f0b1abd622
commit 38cf4d962d
3 changed files with 45 additions and 9 deletions

Binary file not shown.

View File

@ -0,0 +1,28 @@
"""auto
Revision ID: 551167211686
Revises: 80cf84342c5f
Create Date: 2025-06-09 18:13:54.600906
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '551167211686'
down_revision = '80cf84342c5f'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###

View File

@ -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