Add daily overview and part_of_day to food logs

Introduces 'overview' and 'test' routes and templates for daily nutrition summaries. Updates FoodLog model to include 'part_of_day' and 'date_' fields for better log categorization. Adjusts log creation and seed data to support new fields. Removes SSL context from app run for local development.
This commit is contained in:
2025-07-07 14:44:50 +02:00
parent 74ce42c578
commit 30e5e959cd
6 changed files with 182 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ from flask_login import current_user
from application import db
from forms import FoodItemForm, FoodLogForm
from models import FoodItem, FoodLog
from datetime import datetime, timezone
user_bp = Blueprint(
"user",
@@ -163,8 +164,27 @@ def log_food(item_id):
item_id,
current_user.id,
form.amount.data,
part_of_day=0,
)
)
db.session.commit()
return redirect(url_for("user.dashboard"))
return render_template("log_food.html", item_id=item_id, form=form)
@user_bp.route("/overview", methods=["GET"])
def overview():
return render_template("overview.html")
@user_bp.route("/", methods=["GET"])
def test():
today = datetime.now(timezone.utc).date()
logs_today = current_user.food_logs.filter_by(date_=today).all()
logs = {0: [], 1: [], 2: [], 3: []}
for log in logs_today:
logs[log.part_of_day].append(log)
print(logs)
return render_template(
"test.html", date=(today.strftime("%d/%m/%y")), logs=logs
)