From f1a6f8154046a615c2647601c271bce66ce7df08 Mon Sep 17 00:00:00 2001 From: Stef Date: Thu, 7 Aug 2025 20:28:46 +0200 Subject: [PATCH] Add daily nutrition summary to daily log page Calculates and displays total calories, protein, carbs, and fat for the current day on the daily log page. Updates both the route logic and the template to show these nutritional totals in a formatted overview. --- application/user/routes.py | 16 +++++++++++++++- application/user/templates/daily_log.html | 23 +++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/application/user/routes.py b/application/user/routes.py index 83cda44..1ed50ec 100644 --- a/application/user/routes.py +++ b/application/user/routes.py @@ -77,10 +77,24 @@ def daily_log(): today = datetime.now(timezone.utc).date() logs_today = current_user.food_logs.filter_by(date_=today).all() logs = [[], [], [], []] + calories: float = 0 + protein: float = 0 + carbs: float = 0 + fat: float = 0 for log in logs_today: logs[log.part_of_day].append(log) + calories += log.amount * log.food_item.energy_100 / 100 + protein += log.amount * log.food_item.protein_100 / 100 + carbs += log.amount * log.food_item.carbs_100 / 100 + fat += log.amount * log.food_item.fat_100 / 100 return render_template( - "daily_log.html", date=(today.strftime("%d/%m/%y")), logs=logs + "daily_log.html", + date=(today.strftime("%d/%m/%y")), + logs=logs, + calories=calories, + protein=protein, + carbs=carbs, + fat=fat, ) diff --git a/application/user/templates/daily_log.html b/application/user/templates/daily_log.html index fede05e..dbbb73d 100644 --- a/application/user/templates/daily_log.html +++ b/application/user/templates/daily_log.html @@ -12,11 +12,30 @@ Food Nutritional Info

Daily Overview ({{date}})

-

Summary info here...

-
+ +
+
+ Calories: {{ '%.0f' % calories }} kcal +
+
+ Protein: {{ '%.1f' % protein }} g +
+
+ + +
+
+ Carbs: {{ '%.1f' % carbs }} g +
+
+ Fat: {{ '%.1f' % fat }} g +
+
+
+

Eaten today