more, view and edit broken
This commit is contained in:
@ -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 user’s 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'])
|
||||
|
Reference in New Issue
Block a user