broke currently

This commit is contained in:
2025-06-22 16:11:29 -05:00
parent e7a0f5b1be
commit 2bb7a29141
77 changed files with 1748 additions and 2298 deletions

View File

@ -1,30 +1,90 @@
from datetime import datetime
from app import db
from plugins.plant.models import Plant
class GrowLog(db.Model):
__tablename__ = 'grow_logs'
__table_args__ = {'extend_existing': True}
__tablename__ = "grow_logs"
__table_args__ = {"extend_existing": True}
id = db.Column(db.Integer, primary_key=True)
plant_id = db.Column(db.Integer, db.ForeignKey('plant.id'), nullable=False)
title = db.Column(db.String(255), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
id = db.Column(db.Integer, primary_key=True)
plant_id = db.Column(db.Integer, db.ForeignKey("plant.id"), nullable=False)
title = db.Column(db.String(255), nullable=True)
notes = db.Column(db.Text, nullable=True)
is_public = db.Column(db.Boolean, default=False, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
updated_at = db.Column(
db.DateTime,
default=datetime.utcnow,
onupdate=datetime.utcnow,
nullable=False
)
updates = db.relationship('PlantUpdate', backref='grow_log', lazy=True)
# ↔ images uploaded directly to this GrowLog
media_items = db.relationship(
"plugins.media.models.Media",
back_populates="growlog",
foreign_keys="plugins.media.models.Media.growlog_id",
lazy="dynamic",
cascade="all, delete-orphan",
)
# ↔ child updates
updates = db.relationship(
"plugins.growlog.models.PlantUpdate",
back_populates="growlog",
foreign_keys="plugins.growlog.models.PlantUpdate.growlog_id",
lazy="dynamic",
cascade="all, delete-orphan",
)
class PlantUpdate(db.Model):
__tablename__ = 'plant_updates'
__table_args__ = {'extend_existing': True}
__tablename__ = "plant_updates"
__table_args__ = {"extend_existing": True}
id = db.Column(db.Integer, primary_key=True)
plant_id = db.Column(db.Integer, db.ForeignKey('plant.id'), nullable=False)
growlog_id = db.Column(db.Integer, db.ForeignKey('grow_logs.id'), nullable=True)
update_type = db.Column(db.String(50), nullable=False)
description = db.Column(db.Text, nullable=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
id = db.Column(db.Integer, primary_key=True)
growlog_id = db.Column(db.Integer, db.ForeignKey("grow_logs.id"), nullable=False)
description = db.Column(db.Text, nullable=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
# Link to Media.update_id (must match the FK defined there)
media_items = db.relationship('Media', back_populates='update', lazy=True)
# ↔ parent GrowLog.updates
growlog = db.relationship(
"plugins.growlog.models.GrowLog",
back_populates="updates",
foreign_keys=[growlog_id],
lazy="joined",
)
# ↔ images attached via UpdateImage join table
media_items = db.relationship(
"plugins.growlog.models.UpdateImage",
back_populates="update",
foreign_keys="plugins.growlog.models.UpdateImage.update_id",
lazy="dynamic",
cascade="all, delete-orphan",
)
class UpdateImage(db.Model):
__tablename__ = "update_images"
__table_args__ = {"extend_existing": True}
id = db.Column(db.Integer, primary_key=True)
update_id = db.Column(db.Integer, db.ForeignKey("plant_updates.id"), nullable=False)
media_id = db.Column(db.Integer, db.ForeignKey("media.id"), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
# ↔ PlantUpdate.media_items
update = db.relationship(
"plugins.growlog.models.PlantUpdate",
back_populates="media_items",
foreign_keys=[update_id],
lazy="joined",
)
# ↔ the actual Media record
media = db.relationship(
"plugins.media.models.Media",
backref=db.backref("update_images", lazy="dynamic"),
foreign_keys=[media_id],
lazy="joined",
)

View File

@ -1,25 +1,36 @@
{# plugins/growlog/templates/growlog/log_list.html #}
{% import 'core_ui/_media_macros.html' as media %}
{% extends 'core_ui/base.html' %}
{% block content %}
<h2>Logs for Plant #{{ plant.id }}</h2>
<a href="{{ url_for('growlog.add_log', plant_id=plant.id) }}">Add New Log</a>
<ul>
{% for log in logs %}
<li>
<strong>{{ log.timestamp.strftime('%Y-%m-%d') }}:</strong> {{ log.event_type }} - {{ log.note }}
{% if log.media %}
<br><em>Images:</em>
<ul>
{% for image in log.media %}
<li>
<img src="{{ url_for('media.media_file', filename=image.file_url) }}" width="150"><br>
{{ image.caption or "No caption" }}
</li>
{% endfor %}
</ul>
{% endif %}
</li>
<li class="mb-3">
<strong>{{ log.timestamp.strftime('%Y-%m-%d') }}:</strong>
{{ log.event_type }} {{ log.note }}
{% if log.media_items %}
<br><em>Images:</em>
<ul class="list-unstyled ps-3">
{% for image in log.media_items %}
<li class="mb-2">
<img
src="{{ generate_image_url(image) }}"
width="150"
class="img-thumbnail"
alt="Log image"
><br>
{{ image.caption or "No caption" }}
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
{{ media.render_media_list(log.media) }}
{% endblock %}
{# Use shared macro for any remaining media lists #}
{{ media.render_media_list(logs|map(attribute='media_items')|sum, thumb_width=150, current_user=current_user) }}
{% endblock %}