Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Show the difference between planned and logged calories

Roland Geider7ff49d7bc327
diff --git a/wger/nutrition/templates/log/overview.html b/wger/nutrition/templates/log/overview.html
index 25aa1fe72..15ed68f65 100644
--- a/wger/nutrition/templates/log/overview.html
+++ b/wger/nutrition/templates/log/overview.html
@@ -30,21 +30,25 @@
<th>{% trans "Date" %}</th>
<th class="align-right">{% trans "Planned" %}</th>
<th class="align-right">{% trans "Logged" %}</th>
+ <th class="align-right">{% trans "Difference" %}</th>
</tr>
</thead>
<tbody>
- {% for date, items in logs.items %}
+ {% for entry in log_data %}
<tr>
<td>
- <a href="{% url 'nutrition:log:detail' plan.pk date.year date.month date.day %}">
- {{ date|date }}
+ <a href="{% url 'nutrition:log:detail' plan.pk entry.date.year entry.date.month entry.date.day %}">
+ {{ entry.date|date }}
</a>
</td>
<td class="align-right">
- {{ nutritional_data.total.energy|floatformat }} {% trans "kcal" %}
+ {{ entry.planned_calories|floatformat }} {% trans "kcal" %}
</td>
<td class="align-right">
- {{ items.energy }} {% trans "kcal" %}
+ {{ entry.logged_calories }} {% trans "kcal" %}
+ </td>
+ <td class="align-right">
+ {{ entry.difference }}
</td>
</tr>
{% empty %}
diff --git a/wger/nutrition/views/log.py b/wger/nutrition/views/log.py
index c1531998f..5ecc8be3e 100644
--- a/wger/nutrition/views/log.py
+++ b/wger/nutrition/views/log.py
@@ -54,11 +54,18 @@ def overview(request, pk):
if not is_owner and not user.userprofile.ro_access:
return HttpResponseForbidden()
+ log_data = []
+ planned_calories = plan.get_nutritional_values()['total']['energy']
+ for date, items in plan.get_log_overview().items():
+ log_data.append({'date': date,
+ 'planned_calories': planned_calories,
+ 'logged_calories': items['energy'],
+ 'difference': items['energy'] - planned_calories})
+
context = {'plan': plan,
'show_shariff': is_owner,
'is_owner': is_owner,
- 'logs': plan.get_log_overview(),
- 'nutritional_data': plan.get_nutritional_values()}
+ 'log_data': log_data}
return render(request, 'log/overview.html', context)