Recipes phase 4
This commit is contained in:
@@ -25,12 +25,19 @@ def selected_date(request):
|
||||
|
||||
def diary_context(user, day, language='en'):
|
||||
goals, _ = UserSettings.objects.get_or_create(user=user)
|
||||
entries = list(FoodLogEntry.objects.filter(user=user, date=day).select_related('product')
|
||||
entries = list(FoodLogEntry.objects.filter(user=user, date=day).select_related('product', 'recipe_cooking_run')
|
||||
.prefetch_related('attachments').defer('product__raw_data'))
|
||||
for entry in entries:
|
||||
run = getattr(entry, 'recipe_cooking_run', None)
|
||||
entry.nutrition_incomplete = bool(run and any(
|
||||
not row.get('complete', False) for row in run.nutrition_snapshot.values()))
|
||||
totals = {name: sum((getattr(entry, name) or ZERO for entry in entries), ZERO) for name in
|
||||
('calories_kcal', 'carbohydrates_g', 'protein_g', 'fat_g')}
|
||||
fibre_values = [entry.fibre_g for entry in entries if entry.fibre_g is not None]
|
||||
fibre_incomplete = len(fibre_values) != len(entries)
|
||||
fibre_incomplete = len(fibre_values) != len(entries) or any(
|
||||
(getattr(entry, 'recipe_cooking_run', None) and
|
||||
not entry.recipe_cooking_run.nutrition_snapshot.get('fibre_g', {}).get('complete', False))
|
||||
for entry in entries)
|
||||
totals['fibre_g'] = sum(fibre_values, ZERO) if fibre_values or not entries else None
|
||||
meals = []
|
||||
for key, label in MealType.choices:
|
||||
|
||||
Reference in New Issue
Block a user