Preserve date offset in meal logging flow

Adds session storage of the 'offset' parameter to ensure the correct date is used when adding meals and redirecting to the daily log. Updates the add_meal and user routes to handle and validate the offset, improving navigation and data consistency for users logging meals on different days.
This commit is contained in:
2025-08-07 21:15:38 +02:00
parent 4a480eeee3
commit f81329cedd
2 changed files with 13 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ from flask import (
render_template,
flash,
abort,
session,
)
from flask_login import current_user
from application import db
@@ -76,6 +77,7 @@ def daily_log(offset: int = 0):
abort(400) # or handle invalid input
today = datetime.now(timezone.utc).date()
day = today + timedelta(days=offset)
session["offset"] = offset
logs_today = current_user.food_logs.filter_by(date_=day).all()
logs = [[], [], [], []]
calories: float = 0