more, view and edit broken

This commit is contained in:
2025-06-11 05:23:52 -05:00
parent 38cf4d962d
commit e7a0f5b1be
38 changed files with 1008 additions and 141 deletions

View File

@ -8,6 +8,7 @@ from flask import (
url_for,
request,
flash,
current_app,
)
from flask_login import login_required, current_user
from app import db
@ -37,19 +38,44 @@ def inject_image_helper():
@bp.route('/', methods=['GET'])
@login_required
def index():
# 1. Compute per-type stats
total = Plant.query.filter_by(owner_id=current_user.id).count()
raw_types = (
db.session
.query(Plant.plant_type)
.filter_by(owner_id=current_user.id)
.distinct()
.all()
)
plant_types = [pt[0] for pt in raw_types]
stats = {'All': total}
for pt in plant_types:
stats[pt] = Plant.query.filter_by(
owner_id=current_user.id,
plant_type=pt
).count()
# 2. Load ALL this users plants, ordered by common name
plants = (
Plant.query
.filter_by(owner_id=current_user.id)
.order_by(Plant.created_at.desc())
.join(PlantCommonName, Plant.common_id == PlantCommonName.id)
.order_by(PlantCommonName.name)
.options(
db.joinedload(Plant.media),
db.joinedload(Plant.common_name)
)
.all()
)
stats = {
'user_plants': Plant.query.filter_by(owner_id=current_user.id).count(),
'user_images': Media.query.filter_by(uploader_id=current_user.id).count(),
'total_plants': Plant.query.count(),
'total_images': Media.query.count(),
}
return render_template('plant/index.html', plants=plants, stats=stats)
# 3. Render the template (JS will handle filtering & pagination)
return render_template(
'plant/index.html',
plants=plants,
stats=stats,
plant_types=plant_types
)
# ─── CREATE ───────────────────────────────────────────────────────────────────
@bp.route('/create', methods=['GET', 'POST'])