mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 03:10:00 +00:00
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.
This commit is contained in:
@@ -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("/<offset>", 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,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -9,8 +9,17 @@ Food Nutritional Info
|
||||
<!-- Daily Overview Section -->
|
||||
<div class="container">
|
||||
|
||||
<div class="mb-4 p-3 border rounded">
|
||||
<div class="text-center">
|
||||
<div class="mb-4 p-3 border rounded d-flex align-items-center justify-content-between">
|
||||
<!-- Previous Day Button -->
|
||||
<form method="get" action="{{url_for('user.daily_log', offset=offset - 1)}}" class="m-0">
|
||||
<button type="submit" class="btn btn-outline-primary d-flex align-items-center justify-content-center"
|
||||
style="width: 40px; height: 40px;">
|
||||
«
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="flex-grow-1 text-center">
|
||||
<h2>Daily Overview ({{date}})</h2>
|
||||
|
||||
<!-- Row 1 -->
|
||||
@@ -33,9 +42,19 @@ Food Nutritional Info
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Next Day Button -->
|
||||
<form method="get" action="{{url_for('user.daily_log', offset=offset + 1)}}" class="m-0">
|
||||
<button type="submit" class="btn btn-outline-primary d-flex align-items-center justify-content-center"
|
||||
style="width: 40px; height: 40px;">
|
||||
»
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="p-3 border rounded">
|
||||
<div class="text-center">
|
||||
<h2>Eaten today</h2>
|
||||
|
||||
Reference in New Issue
Block a user