From e3119a69fce7dccdb0e5753fe6d5736ca50fbbd7 Mon Sep 17 00:00:00 2001 From: Stef Date: Thu, 7 Aug 2025 20:49:10 +0200 Subject: [PATCH] Add day navigation to daily log view Updated the daily log route and template to support viewing logs for previous and next days using an offset parameter. The default redirect now points to the daily log instead of the dashboard. The daily_log.html template includes navigation buttons for moving between days. --- app.py | 2 +- application/user/routes.py | 15 +++++++++++---- application/user/templates/daily_log.html | 23 +++++++++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index b57b369..a861abe 100644 --- a/app.py +++ b/app.py @@ -34,7 +34,7 @@ app.register_blueprint(add_meal_bp) def default_return(next_page: Optional[str] = None): - return redirect(url_for("user.dashboard")) + return redirect(url_for("user.daily_log")) if next_page: return redirect(next_page) if current_user.is_admin: diff --git a/application/user/routes.py b/application/user/routes.py index 30913ae..12aa67d 100644 --- a/application/user/routes.py +++ b/application/user/routes.py @@ -10,7 +10,7 @@ from flask_login import current_user from application import db from forms import FoodItemForm from models import FoodItem, FoodLog -from datetime import datetime, timezone +from datetime import datetime, timezone, timedelta user_bp = Blueprint( "user", @@ -68,9 +68,15 @@ def edit_food_item(id: int): @user_bp.route("/", methods=["GET"]) -def daily_log(): +@user_bp.route("/", methods=["GET"]) +def daily_log(offset: int = 0): + try: + offset = int(offset) + except ValueError: + abort(400) # or handle invalid input today = datetime.now(timezone.utc).date() - logs_today = current_user.food_logs.filter_by(date_=today).all() + day = today + timedelta(days=offset) + logs_today = current_user.food_logs.filter_by(date_=day).all() logs = [[], [], [], []] calories: float = 0 protein: float = 0 @@ -84,12 +90,13 @@ def daily_log(): fat += log.amount * log.food_item.fat_100 / 100 return render_template( "daily_log.html", - date=(today.strftime("%d/%m/%y")), + date=(day.strftime("%d/%m/%y")), logs=logs, calories=calories, protein=protein, carbs=carbs, fat=fat, + offset=offset, ) diff --git a/application/user/templates/daily_log.html b/application/user/templates/daily_log.html index dbbb73d..cc21699 100644 --- a/application/user/templates/daily_log.html +++ b/application/user/templates/daily_log.html @@ -9,8 +9,17 @@ Food Nutritional Info
-
-
+
+ +
+ +
+ + +

Daily Overview ({{date}})

@@ -33,9 +42,19 @@ Food Nutritional Info
+ + +
+ +
+ +

Eaten today