Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Show more info in the nutrition diary detail page

Roland Geiderb306ccc5cd57
diff --git a/wger/core/templatetags/wger_extras.py b/wger/core/templatetags/wger_extras.py
index 8ec4d518a..8666e5040 100644
--- a/wger/core/templatetags/wger_extras.py
+++ b/wger/core/templatetags/wger_extras.py
@@ -158,6 +158,22 @@ def get_item(dictionary, key):
return dictionary.get(key)
+def minus(a, b):
+ """
+ Simple function that subtracts two values in a template
+ """
+ return a - b
+
+
+def is_positive(a):
+ """
+ Simple function that checks whether one value is bigger than the other
+ """
+ return a > 0
+
+
@register.simple_tag
def fa_class(class_name='', icon_type='fas', fixed_width=True):
"""
diff --git a/wger/nutrition/models.py b/wger/nutrition/models.py
index 87b319d11..33c532aca 100644
--- a/wger/nutrition/models.py
+++ b/wger/nutrition/models.py
@@ -653,7 +653,7 @@ class BaseMealItem(object):
def get_nutritional_values(self, use_metric=True):
"""
- Sums the nutrional info for the ingredient in the MealItem
+ Sums the nutritional info for the ingredient in the MealItem
:param use_metric Flag that controls the units used
"""
diff --git a/wger/nutrition/templates/log/detail.html b/wger/nutrition/templates/log/detail.html
index 9b85857dc..be634772f 100644
--- a/wger/nutrition/templates/log/detail.html
+++ b/wger/nutrition/templates/log/detail.html
@@ -31,6 +31,7 @@
<th>{% trans "Macronutrients" %}</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>
@@ -38,46 +39,110 @@
<td>{% trans "Energy" %}</td>
<td class="align-right">{{ nutritional_data.total.energy|floatformat:0 }} {% trans "kcal" %}</td>
<td class="align-right">{{ log_summary.energy|floatformat:0 }} {% trans "kcal" %}</td>
+ <td class="align-right">
+ {% with diff=nutritional_data.total.energy|minus:log_summary.energy %}
+ {% if diff|is_positive %}
+ +
+ {% endif %}
+ {{ diff|floatformat:0 }}
+ {% endwith %}
+ </td>
</tr>
<tr>
<td>{% trans "Protein" %}</td>
<td class="align-right">{{ nutritional_data.total.protein|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>
<td class="align-right">{{ log_summary.protein|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>
+ <td class="align-right">
+ {% with diff=nutritional_data.total.protein|minus:log_summary.protein %}
+ {% if diff|is_positive %}
+ +
+ {% endif %}
+ {{ diff|floatformat:0 }}
+ {% endwith %}
+ </td>
</tr>
<tr>
<td>{% trans "Carbohydrates" %}</td>
<td class="align-right">{{ nutritional_data.total.carbohydrates|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>
<td class="align-right">{{ log_summary.carbohydrates|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>
+ <td class="align-right">
+ {% with diff=nutritional_data.total.carbohydrates|minus:log_summary.carbohydrates %}
+ {% if diff|is_positive %}
+ +
+ {% endif %}
+ {{ diff|floatformat:0 }}
+ {% endwith %}
+ </td>
</tr>
<tr>
<td class="pl-4">{% trans "Sugar content in carbohydrates" %}</td>
<td class="align-right">{{ nutritional_data.total.carbohydrates_sugar|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>
<td class="align-right">{{ log_summary.carbohydrates_sugar|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>
+ <td class="align-right">
+ {% with diff=nutritional_data.total.carbohydrates_sugar|minus:log_summary.carbohydrates_sugar %}
+ {% if diff|is_positive %}
+ +
+ {% endif %}
+ {{ diff|floatformat:0 }}
+ {% endwith %}
+ </td>
</tr>
<tr>
<td>{% trans "Fat" %}</td>
<td class="align-right">{{ nutritional_data.total.fat|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>
<td class="align-right">{{ log_summary.fat|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>
+ <td class="align-right">
+ {% with diff=nutritional_data.total.fat|minus:log_summary.fat %}
+ {% if diff|is_positive %}
+ +
+ {% endif %}
+ {{ diff|floatformat:0 }}
+ {% endwith %}
+ </td>
</tr>
<tr>
<td class="pl-4">{% trans "Saturated fat content in fats" %}</td>
<td class="align-right">{{ nutritional_data.total.fat_saturated|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>
<td class="align-right">{{ log_summary.fat_saturated|floatformat:1 }} {% trans_weight_unit 'g' owner_user %}</td>
+ <td class="align-right">
+ {% with diff=nutritional_data.total.fat_saturated|minus:log_summary.fat_saturated %}
+ {% if diff|is_positive %}
+ +
+ {% endif %}
+ {{ diff|floatformat:0 }}
+ {% endwith %}
+ </td>
</tr>
<tr>
- <th colspan="3">{% trans "Others" %}</th>
+ <th colspan="4">{% trans "Others" %}</th>
</tr>
<tr>
<td>{% trans "Fibres" %}</td>
<td class="align-right">{{ nutritional_data.total.fibres|floatformat }} {% trans_weight_unit 'g' owner_user %}</td>
<td class="align-right">{{ log_summary.fibres|floatformat }} {% trans_weight_unit 'g' owner_user %}</td>
+ <td class="align-right">
+ {% with diff=nutritional_data.total.fibres|minus:log_summary.fibres %}
+ {% if diff|is_positive %}
+ +
+ {% endif %}
+ {{ diff|floatformat:0 }}
+ {% endwith %}
+ </td>
</tr>
<tr>
<td>{% trans "Sodium" %}</td>
<td class="align-right">{{ nutritional_data.total.sodium|floatformat }} {% trans_weight_unit 'g' owner_user %}</td>
<td class="align-right">{{ log_summary.sodium|floatformat }} {% trans_weight_unit 'g' owner_user %}</td>
+ <td class="align-right">
+ {% with diff=nutritional_data.total.sodium|minus:log_summary.sodium %}
+ {% if diff|is_positive %}
+ +
+ {% endif %}
+ {{ diff|floatformat:0 }}
+ {% endwith %}
+ </td>
</tr>
</tbody>
</table>
@@ -105,6 +170,17 @@
{{ entry.amount|floatformat:"0" }}{% trans "g" %}
{% endif %}
{{ entry.ingredient }}
+ <p class="small text-muted">
+ {% trans "Protein" %}: {{entry.get_nutritional_values.protein|floatformat:"1"}} <br>
+ {% trans "Carbohydrates" %}: {{entry.get_nutritional_values.carbohydrates|floatformat:"1"}} ({{entry.get_nutritional_values.carbohydrates_sugar|floatformat:"1"}})<br>
+ {% trans "Fat" %}: {{entry.get_nutritional_values.fat|floatformat:"1"}} ({{entry.get_nutritional_values.fat|floatformat:"1"}})<br>
+ {% if entry.get_nutritional_values.fibres %}
+ {% trans "Fibres" %}: {{entry.get_nutritional_values.fibres|floatformat:"1"}}<br>
+ {% endif %}
+ {% if entry.get_nutritional_values.sodium %}
+ {% trans "Sodium" %}: {{entry.get_nutritional_values.sodium|floatformat:"1"}}<br>
+ {% endif %}
+ </p>
</td>
<td class="align-right">