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:
2
app.py
2
app.py
@@ -34,7 +34,7 @@ app.register_blueprint(add_meal_bp)
|
|||||||
|
|
||||||
|
|
||||||
def default_return(next_page: Optional[str] = None):
|
def default_return(next_page: Optional[str] = None):
|
||||||
return redirect(url_for("user.dashboard"))
|
return redirect(url_for("user.daily_log"))
|
||||||
if next_page:
|
if next_page:
|
||||||
return redirect(next_page)
|
return redirect(next_page)
|
||||||
if current_user.is_admin:
|
if current_user.is_admin:
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from flask_login import current_user
|
|||||||
from application import db
|
from application import db
|
||||||
from forms import FoodItemForm
|
from forms import FoodItemForm
|
||||||
from models import FoodItem, FoodLog
|
from models import FoodItem, FoodLog
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone, timedelta
|
||||||
|
|
||||||
user_bp = Blueprint(
|
user_bp = Blueprint(
|
||||||
"user",
|
"user",
|
||||||
@@ -68,9 +68,15 @@ def edit_food_item(id: int):
|
|||||||
|
|
||||||
|
|
||||||
@user_bp.route("/", methods=["GET"])
|
@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()
|
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 = [[], [], [], []]
|
logs = [[], [], [], []]
|
||||||
calories: float = 0
|
calories: float = 0
|
||||||
protein: float = 0
|
protein: float = 0
|
||||||
@@ -84,12 +90,13 @@ def daily_log():
|
|||||||
fat += log.amount * log.food_item.fat_100 / 100
|
fat += log.amount * log.food_item.fat_100 / 100
|
||||||
return render_template(
|
return render_template(
|
||||||
"daily_log.html",
|
"daily_log.html",
|
||||||
date=(today.strftime("%d/%m/%y")),
|
date=(day.strftime("%d/%m/%y")),
|
||||||
logs=logs,
|
logs=logs,
|
||||||
calories=calories,
|
calories=calories,
|
||||||
protein=protein,
|
protein=protein,
|
||||||
carbs=carbs,
|
carbs=carbs,
|
||||||
fat=fat,
|
fat=fat,
|
||||||
|
offset=offset,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,17 @@ Food Nutritional Info
|
|||||||
<!-- Daily Overview Section -->
|
<!-- Daily Overview Section -->
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
<div class="mb-4 p-3 border rounded">
|
<div class="mb-4 p-3 border rounded d-flex align-items-center justify-content-between">
|
||||||
<div class="text-center">
|
<!-- 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>
|
<h2>Daily Overview ({{date}})</h2>
|
||||||
|
|
||||||
<!-- Row 1 -->
|
<!-- Row 1 -->
|
||||||
@@ -33,9 +42,19 @@ Food Nutritional Info
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="p-3 border rounded">
|
<div class="p-3 border rounded">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2>Eaten today</h2>
|
<h2>Eaten today</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user