mirror of
https://github.com/sstent/foodplanner.git
synced 2026-01-25 03:01:35 +00:00
fixed food details not loading on details tab
This commit is contained in:
@@ -216,17 +216,24 @@ async def detailed(request: Request, person: str = "Sarah", plan_date: str = Non
|
||||
|
||||
# Show individual foods in template meals
|
||||
for mf in tm.meal.meal_foods:
|
||||
try:
|
||||
serving_size_value = float(mf.food.serving_size)
|
||||
num_servings = mf.quantity / serving_size_value if serving_size_value != 0 else 0
|
||||
except (ValueError, TypeError):
|
||||
num_servings = 0 # Fallback for invalid serving_size
|
||||
|
||||
foods.append({
|
||||
'name': mf.food.name,
|
||||
'quantity': mf.quantity,
|
||||
'total_grams': mf.quantity,
|
||||
'num_servings': num_servings,
|
||||
'serving_size': mf.food.serving_size,
|
||||
'serving_unit': mf.food.serving_unit,
|
||||
'calories': mf.food.calories * mf.quantity,
|
||||
'protein': mf.food.protein * mf.quantity,
|
||||
'carbs': mf.food.carbs * mf.quantity,
|
||||
'fat': mf.food.fat * mf.quantity,
|
||||
'fiber': (mf.food.fiber or 0) * mf.quantity,
|
||||
'sodium': (mf.food.sodium or 0) * mf.quantity,
|
||||
'calories': mf.food.calories * num_servings,
|
||||
'protein': mf.food.protein * num_servings,
|
||||
'carbs': mf.food.carbs * num_servings,
|
||||
'fat': mf.food.fat * num_servings,
|
||||
'fiber': (mf.food.fiber or 0) * num_servings,
|
||||
'sodium': (mf.food.sodium or 0) * num_servings,
|
||||
})
|
||||
|
||||
meal_details.append({
|
||||
@@ -298,32 +305,46 @@ async def detailed(request: Request, person: str = "Sarah", plan_date: str = Non
|
||||
|
||||
# Show base meal foods
|
||||
for mf in tracked_meal.meal.meal_foods:
|
||||
try:
|
||||
serving_size_value = float(mf.food.serving_size)
|
||||
num_servings = mf.quantity / serving_size_value if serving_size_value != 0 else 0
|
||||
except (ValueError, TypeError):
|
||||
num_servings = 0 # Fallback for invalid serving_size
|
||||
|
||||
foods.append({
|
||||
'name': mf.food.name,
|
||||
'quantity': mf.quantity,
|
||||
'total_grams': mf.quantity,
|
||||
'num_servings': num_servings,
|
||||
'serving_size': mf.food.serving_size,
|
||||
'serving_unit': mf.food.serving_unit,
|
||||
'calories': mf.food.calories * mf.quantity,
|
||||
'protein': mf.food.protein * mf.quantity,
|
||||
'carbs': mf.food.carbs * mf.quantity,
|
||||
'fat': mf.food.fat * mf.quantity,
|
||||
'fiber': (mf.food.fiber or 0) * mf.quantity,
|
||||
'sodium': (mf.food.sodium or 0) * mf.quantity,
|
||||
'calories': mf.food.calories * num_servings,
|
||||
'protein': mf.food.protein * num_servings,
|
||||
'carbs': mf.food.carbs * num_servings,
|
||||
'fat': mf.food.fat * num_servings,
|
||||
'fiber': (mf.food.fiber or 0) * num_servings,
|
||||
'sodium': (mf.food.sodium or 0) * num_servings,
|
||||
})
|
||||
|
||||
# Show custom tracked foods (overrides/additions)
|
||||
for tracked_food in tracked_meal.tracked_foods:
|
||||
try:
|
||||
serving_size_value = float(tracked_food.food.serving_size)
|
||||
num_servings = tracked_food.quantity / serving_size_value if serving_size_value != 0 else 0
|
||||
except (ValueError, TypeError):
|
||||
num_servings = 0 # Fallback for invalid serving_size
|
||||
|
||||
foods.append({
|
||||
'name': f"{tracked_food.food.name} {'(override)' if tracked_food.is_override else '(addition)'}",
|
||||
'quantity': tracked_food.quantity,
|
||||
'total_grams': tracked_food.quantity,
|
||||
'num_servings': num_servings,
|
||||
'serving_size': tracked_food.food.serving_size,
|
||||
'serving_unit': tracked_food.food.serving_unit,
|
||||
'calories': tracked_food.food.calories * tracked_food.quantity,
|
||||
'protein': tracked_food.food.protein * tracked_food.quantity,
|
||||
'carbs': tracked_food.food.carbs * tracked_food.quantity,
|
||||
'fat': tracked_food.food.fat * tracked_food.quantity,
|
||||
'fiber': (tracked_food.food.fiber or 0) * tracked_food.quantity,
|
||||
'sodium': (tracked_food.food.sodium or 0) * tracked_food.quantity,
|
||||
'calories': tracked_food.food.calories * num_servings,
|
||||
'protein': tracked_food.food.protein * num_servings,
|
||||
'carbs': tracked_food.food.carbs * num_servings,
|
||||
'fat': tracked_food.food.fat * num_servings,
|
||||
'fiber': (tracked_food.food.fiber or 0) * num_servings,
|
||||
'sodium': (tracked_food.food.sodium or 0) * num_servings,
|
||||
})
|
||||
|
||||
meal_details.append({
|
||||
@@ -370,17 +391,24 @@ async def detailed(request: Request, person: str = "Sarah", plan_date: str = Non
|
||||
|
||||
foods = []
|
||||
for mf in plan.meal.meal_foods:
|
||||
try:
|
||||
serving_size_value = float(mf.food.serving_size)
|
||||
num_servings = mf.quantity / serving_size_value if serving_size_value != 0 else 0
|
||||
except (ValueError, TypeError):
|
||||
num_servings = 0 # Fallback for invalid serving_size
|
||||
|
||||
foods.append({
|
||||
'name': mf.food.name,
|
||||
'quantity': mf.quantity,
|
||||
'total_grams': mf.quantity,
|
||||
'num_servings': num_servings,
|
||||
'serving_size': mf.food.serving_size,
|
||||
'serving_unit': mf.food.serving_unit,
|
||||
'calories': mf.food.calories * mf.quantity,
|
||||
'protein': mf.food.protein * mf.quantity,
|
||||
'carbs': mf.food.carbs * mf.quantity,
|
||||
'fat': mf.food.fat * mf.quantity,
|
||||
'fiber': (mf.food.fiber or 0) * mf.quantity,
|
||||
'sodium': (mf.food.sodium or 0) * mf.quantity,
|
||||
'calories': mf.food.calories * num_servings,
|
||||
'protein': mf.food.protein * num_servings,
|
||||
'carbs': mf.food.carbs * num_servings,
|
||||
'fat': mf.food.fat * num_servings,
|
||||
'fiber': (mf.food.fiber or 0) * num_servings,
|
||||
'sodium': (mf.food.sodium or 0) * num_servings,
|
||||
})
|
||||
|
||||
meal_details.append({
|
||||
|
||||
@@ -807,35 +807,49 @@ async def detailed_tracked_day(request: Request, person: str = "Sarah", date: Op
|
||||
foods = []
|
||||
# Add foods from the base meal definition
|
||||
for mf in tracked_meal.meal.meal_foods:
|
||||
try:
|
||||
serving_size_value = float(mf.food.serving_size)
|
||||
num_servings = mf.quantity / serving_size_value if serving_size_value != 0 else 0
|
||||
except (ValueError, TypeError):
|
||||
num_servings = 0 # Fallback for invalid serving_size
|
||||
|
||||
foods.append({
|
||||
'name': mf.food.name,
|
||||
'quantity': mf.quantity,
|
||||
'total_grams': mf.quantity,
|
||||
'num_servings': num_servings,
|
||||
'serving_size': mf.food.serving_size,
|
||||
'serving_unit': mf.food.serving_unit,
|
||||
'calories': mf.food.calories * mf.quantity,
|
||||
'protein': mf.food.protein * mf.quantity,
|
||||
'carbs': mf.food.carbs * mf.quantity,
|
||||
'fat': mf.food.fat * mf.quantity,
|
||||
'fiber': (mf.food.fiber or 0) * mf.quantity,
|
||||
'sugar': (mf.food.sugar or 0) * mf.quantity,
|
||||
'sodium': (mf.food.sodium or 0) * mf.quantity,
|
||||
'calcium': (mf.food.calcium or 0) * mf.quantity,
|
||||
'calories': mf.food.calories * num_servings,
|
||||
'protein': mf.food.protein * num_servings,
|
||||
'carbs': mf.food.carbs * num_servings,
|
||||
'fat': mf.food.fat * num_servings,
|
||||
'fiber': (mf.food.fiber or 0) * num_servings,
|
||||
'sugar': (mf.food.sugar or 0) * num_servings,
|
||||
'sodium': (mf.food.sodium or 0) * num_servings,
|
||||
'calcium': (mf.food.calcium or 0) * num_servings,
|
||||
})
|
||||
# Add custom tracked foods (overrides or additions)
|
||||
for tmf in tracked_meal.tracked_foods:
|
||||
try:
|
||||
serving_size_value = float(tmf.food.serving_size)
|
||||
num_servings = tmf.quantity / serving_size_value if serving_size_value != 0 else 0
|
||||
except (ValueError, TypeError):
|
||||
num_servings = 0 # Fallback for invalid serving_size
|
||||
|
||||
foods.append({
|
||||
'name': tmf.food.name,
|
||||
'quantity': tmf.quantity,
|
||||
'total_grams': tmf.quantity,
|
||||
'num_servings': num_servings,
|
||||
'serving_size': tmf.food.serving_size,
|
||||
'serving_unit': tmf.food.serving_unit,
|
||||
'calories': tmf.food.calories * tmf.quantity,
|
||||
'protein': tmf.food.protein * tmf.quantity,
|
||||
'carbs': tmf.food.carbs * tmf.quantity,
|
||||
'fat': tmf.food.fat * tmf.quantity,
|
||||
'fiber': (tmf.food.fiber or 0) * tmf.quantity,
|
||||
'sugar': (tmf.food.sugar or 0) * tmf.quantity,
|
||||
'sodium': (tmf.food.sodium or 0) * tmf.quantity,
|
||||
'calcium': (tmf.food.calcium or 0) * tmf.quantity,
|
||||
'calories': tmf.food.calories * num_servings,
|
||||
'protein': tmf.food.protein * num_servings,
|
||||
'carbs': tmf.food.carbs * num_servings,
|
||||
'fat': tmf.food.fat * num_servings,
|
||||
'fiber': (tmf.food.fiber or 0) * num_servings,
|
||||
'sugar': (tmf.food.sugar or 0) * num_servings,
|
||||
'sodium': (tmf.food.sodium or 0) * num_servings,
|
||||
'calcium': (tmf.food.calcium or 0) * num_servings,
|
||||
})
|
||||
|
||||
meal_details.append({
|
||||
|
||||
@@ -166,15 +166,15 @@
|
||||
</td>
|
||||
<td>
|
||||
<div class="serving-info">
|
||||
{{ meal_food.quantity }} × {{ meal_food.serving_size }}{{ meal_food.serving_unit }}
|
||||
{{ "%.1f"|format(meal_food.num_servings) }} × {{ meal_food.serving_size }}{{ meal_food.serving_unit }} ({{ "%.0f"|format(meal_food.total_grams) }}g)
|
||||
</div>
|
||||
</td>
|
||||
<td class="nutrient-value">{{ "%.0f"|format(meal_food.calories) }}</td>
|
||||
<td class="nutrient-value">{{ "%.1f"|format(meal_food.protein) }}g</td>
|
||||
<td class="nutrient-value">{{ "%.1f"|format(meal_food.carbs) }}g</td>
|
||||
<td class="nutrient-value">{{ "%.1f"|format(meal_food.fat) }}g</td>
|
||||
<td class="nutrient-value">{{ "%.1f"|format(meal_food['fiber']|float) }}g</td>
|
||||
<td class="nutrient-value">{{ "%.0f"|format(meal_food['sodium']|float) }}mg</td>
|
||||
<td class="nutrient-value">{{ "%.1f"|format(meal_food.fiber) }}g</td>
|
||||
<td class="nutrient-value">{{ "%.0f"|format(meal_food.sodium) }}mg</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<!-- Meal Totals Row -->
|
||||
|
||||
@@ -158,15 +158,15 @@
|
||||
</td>
|
||||
<td>
|
||||
<div class="serving-info">
|
||||
{{ "%.1f"|format(meal_food.quantity) }} × {{ meal_food.serving_size }}{{ meal_food.serving_unit }}
|
||||
{{ "%.1f"|format(meal_food.num_servings) }} × {{ meal_food.serving_size }}{{ meal_food.serving_unit }} ({{ "%.0f"|format(meal_food.total_grams) }}g)
|
||||
</div>
|
||||
</td>
|
||||
<td class="nutrient-value">{{ "%.0f"|format(meal_food.calories) }}</td>
|
||||
<td class="nutrient-value">{{ "%.1f"|format(meal_food.protein) }}g</td>
|
||||
<td class="nutrient-value">{{ "%.1f"|format(meal_food.carbs) }}g</td>
|
||||
<td class="nutrient-value">{{ "%.1f"|format(meal_food.fat) }}g</td>
|
||||
<td class="nutrient-value">{{ "%.1f"|format(meal_food['fiber']|float) }}g</td>
|
||||
<td class="nutrient-value">{{ "%.0f"|format(meal_food['sodium']|float) }}mg</td>
|
||||
<td class="nutrient-value">{{ "%.1f"|format(meal_food.fiber) }}g</td>
|
||||
<td class="nutrient-value">{{ "%.0f"|format(meal_food.sodium) }}mg</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<!-- Meal Totals Row -->
|
||||
|
||||
Reference in New Issue
Block a user