This commit is contained in:
2025-05-18 05:21:16 -05:00
parent 132073ca19
commit c19bedc54a
65 changed files with 705 additions and 575 deletions

View File

@ -0,0 +1 @@
# growlog plugin init

15
plugins/growlog/forms.py Normal file
View File

@ -0,0 +1,15 @@
from flask_wtf import FlaskForm
from wtforms import TextAreaField, SelectField, SubmitField
from wtforms.validators import DataRequired, Length
class GrowLogForm(FlaskForm):
event_type = SelectField('Event Type', choices=[
('water', 'Watered'),
('fertilizer', 'Fertilized'),
('repot', 'Repotted'),
('note', 'Note'),
('pest', 'Pest Observed')
], validators=[DataRequired()])
note = TextAreaField('Notes', validators=[Length(max=1000)])
submit = SubmitField('Add Log')

15
plugins/growlog/models.py Normal file
View File

@ -0,0 +1,15 @@
from app import db
from datetime import datetime
class GrowLog(db.Model):
__tablename__ = 'grow_logs'
id = db.Column(db.Integer, primary_key=True)
plant_id = db.Column(db.Integer, db.ForeignKey('plants.id'), nullable=False)
timestamp = db.Column(db.DateTime, default=datetime.utcnow)
event_type = db.Column(db.String(64), nullable=False)
note = db.Column(db.Text)
media = db.relationship("Media", backref="growlog", lazy=True)
def __repr__(self):
return f"<GrowLog {self.event_type} @ {self.timestamp}>"

View File

@ -0,0 +1 @@
{ "name": "growlog", "version": "1.0", "description": "Tracks time-based plant care logs" }

31
plugins/growlog/routes.py Normal file
View File

@ -0,0 +1,31 @@
from flask import Blueprint, render_template, redirect, url_for, request
from flask_login import login_required
from app import db
from .models import GrowLog
from .forms import GrowLogForm
from plugins.plant.models import Plant
bp = Blueprint('growlog', __name__, template_folder='templates')
@bp.route('/plants/<int:plant_id>/logs')
@login_required
def view_logs(plant_id):
plant = Plant.query.get_or_404(plant_id)
logs = GrowLog.query.filter_by(plant_id=plant.id).order_by(GrowLog.timestamp.desc()).all()
return render_template('growlog/log_list.html', plant=plant, logs=logs)
@bp.route('/plants/<int:plant_id>/logs/add', methods=['GET', 'POST'])
@login_required
def add_log(plant_id):
plant = Plant.query.get_or_404(plant_id)
form = GrowLogForm()
if form.validate_on_submit():
log = GrowLog(
plant_id=plant.id,
event_type=form.event_type.data,
note=form.note.data
)
db.session.add(log)
db.session.commit()
return redirect(url_for('growlog.view_logs', plant_id=plant.id))
return render_template('growlog/log_form.html', form=form, plant=plant)

View File

@ -0,0 +1,10 @@
{% extends 'base.html' %}
{% block content %}
<h2>Add Log for Plant #{{ plant.id }}</h2>
<form method="POST">
{{ form.hidden_tag() }}
<p>{{ form.event_type.label }}<br>{{ form.event_type() }}</p>
<p>{{ form.note.label }}<br>{{ form.note(rows=4) }}</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}

View File

@ -0,0 +1,25 @@
{% import 'core_ui/_media_macros.html' as media %}
{% extends '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>
{% endfor %}
</ul>
{{ media.render_media_list(log.media) }}
{% endblock %}