Self hosted FLOSS fitness/workout, nutrition and weight tracker
Show detailed nutrition data for each ingredient
Roland Geiderd83c0222b33c
diff --git a/wger/nutrition/models.py b/wger/nutrition/models.pyindex 416353efc..309c40f0e 100644--- a/wger/nutrition/models.py+++ b/wger/nutrition/models.py@@ -593,40 +593,43 @@ class MealItem(models.Model):self.weight_unit.amount *self.weight_unit.gramm)- nutritional_info['energy'] += self.ingredient.energy * item_weight / 100- nutritional_info['protein'] += self.ingredient.protein * item_weight / 100- nutritional_info['carbohydrates'] += self.ingredient.carbohydrates * \- item_weight / 100+ nutritional_info['energy'] += (self.ingredient.energy * item_weight / 100) \+ .quantize(TWOPLACES)+ nutritional_info['protein'] += (self.ingredient.protein * item_weight / 100) \+ .quantize(TWOPLACES)+ nutritional_info['carbohydrates'] += (self.ingredient.carbohydrates *+ item_weight / 100).quantize(TWOPLACES)if self.ingredient.carbohydrates_sugar:- nutritional_info['carbohydrates_sugar'] += \- self.ingredient.carbohydrates_sugar * \- item_weight / 100+ nutritional_info['carbohydrates_sugar'] += (self.ingredient.carbohydrates_sugar *+ item_weight / 100).quantize(TWOPLACES)- nutritional_info['fat'] += self.ingredient.fat * item_weight / 100+ nutritional_info['fat'] += (self.ingredient.fat *+ item_weight / 100).quantize(TWOPLACES)if self.ingredient.fat_saturated:- nutritional_info['fat_saturated'] += self.ingredient.fat_saturated * \- item_weight / 100+ nutritional_info['fat_saturated'] += (self.ingredient.fat_saturated *+ item_weight / 100).quantize(TWOPLACES)if self.ingredient.fibres:- nutritional_info['fibres'] += self.ingredient.fibres * \- item_weight / 100+ nutritional_info['fibres'] += (self.ingredient.fibres *+ item_weight / 100).quantize(TWOPLACES)if self.ingredient.sodium:- nutritional_info['sodium'] += self.ingredient.sodium * \- item_weight / 100+ nutritional_info['sodium'] += (self.ingredient.sodium *+ item_weight / 100).quantize(TWOPLACES)return nutritional_infodef get_nutritional_values_percent(self):'''- Calculates the percentage each macronutrients contribute to the+ Calculates the percentage each macronutrient contributes to thetotal energy (approximation, since the factors 4, 4 and 9 are onlya rule of thumb)'''values = self.get_nutritional_values()- result = {'protein': values['energy'] / values['protein'] * 4,- 'carbohydrates': values['energy'] / values['carbohydrates'] * 4,- 'fat': values['energy'] / values['fat'] * 9}+ result = {'protein': values['energy'] / values['protein'] * PROTEIN_FACTOR,+ 'carbohydrates': values['energy'] / values['carbohydrates'] *+ CARBOHYDRATES_FACTOR,+ 'fat': values['energy'] / values['fat'] * FAT_FACTOR}return resultdiff --git a/wger/nutrition/templates/plan/view.html b/wger/nutrition/templates/plan/view.htmlindex ba34bf030..2699914a5 100644--- a/wger/nutrition/templates/plan/view.html+++ b/wger/nutrition/templates/plan/view.html@@ -37,13 +37,19 @@ $(document).ready(function() {<tr><th class="ym-g15">{% trans "Meal" %}</th><th>{% trans "Contents" %}</th>+ <th>{% trans "Energy" %}</th>+ <th>{% trans "Protein" %}</th>+ <th>{% trans "Carbohydrates" %}</th>+ <th>{% trans "Fat" %}</th></tr></thead><tbody>{% for meal in plan.meal_set.select_related %}+ {% for item in meal.mealitem_set.select_related %}<tr>- <td>- {% trans "Nr."%} {{ forloop.counter }}+ {% ifchanged meal.pk %}+ <td rowspan="{{meal.mealitem_set.count}}">+ {% trans "Nr."%} {{ forloop.parentloop.counter }}{% if meal.time %} – {{meal.time|time:"H:i"}}{% endif %}<div class="editoptions">@@ -75,46 +81,50 @@ $(document).ready(function() {</a></div></td>+ {% endifchanged %}<td>- <ul>- {% for item in meal.mealitem_set.select_related %}- <li>- {% if item.get_unit_type == MEALITEM_WEIGHT_GRAM %}{{ item.amount|floatformat:"0" }}g- {% else %}- {{ item.amount|floatformat:"0" }} × {{ item.weight_unit.unit.name }}- {% endif %}- {{ item.ingredient.name }}+ {% if item.get_unit_type == MEALITEM_WEIGHT_GRAM %}{{ item.amount|floatformat:"0" }}g+ {% else %}+ {{ item.amount|floatformat:"0" }} × {{ item.weight_unit.unit.name }}+ {% endif %}+ {{ item.ingredient.name }}- <span class="editoptions">- <a href="{% url 'wger.nutrition.views.meal_item.delete_meal_item' item.id %}"- title="{% trans 'Delete' %}"- class="delete-mealitem">- <img src="{% static 'images/icons/trash.svg' %}"- width="16"- height="16"- alt="{% trans 'Delete' %}">- </a>- <a href="{% url 'mealitem-edit' item.id %}"- title="{% trans 'Edit' %}"- class="modal-dialog edit-meal edit-mealitem">- <img src="{% static 'images/icons/edit.svg' %}"- width="16"- height="16"- alt="{% trans 'Edit' %}">- </a>- </span>- </li>- {% empty %}- <a href="{% url 'mealitem-add' meal.id %}"- title="{% trans 'Add one now.' %}"- class="modal-dialog edit-meal btn btn-block">- {% trans "No items for this meal." %}- {% trans "Add one now."%}+ <span class="editoptions">+ <a href="{% url 'wger.nutrition.views.meal_item.delete_meal_item' item.id %}"+ title="{% trans 'Delete' %}"+ class="delete-mealitem">+ <img src="{% static 'images/icons/trash.svg' %}"+ width="16"+ height="16"+ alt="{% trans 'Delete' %}"></a>- {% endfor %}- </ul>- </td>- </tr>+ <a href="{% url 'mealitem-edit' item.id %}"+ title="{% trans 'Edit' %}"+ class="modal-dialog edit-meal edit-mealitem">+ <img src="{% static 'images/icons/edit.svg' %}"+ width="16"+ height="16"+ alt="{% trans 'Edit' %}">+ </a>+ </span>+ </td>+ <td>{{item.get_nutritional_values.energy|floatformat}}</td>+ <td>{{item.get_nutritional_values.protein|floatformat}}</td>+ <td>{{item.get_nutritional_values.carbohydrates|floatformat}}</td>+ <td>{{item.get_nutritional_values.fat|floatformat}}</td>+</tr>+ {% empty %}+ <tr>+ <td colspan="7">+ <a href="{% url 'mealitem-add' meal.id %}"+ title="{% trans 'Add one now.' %}"+ class="modal-dialog edit-meal btn btn-block">+ {% trans "No items for this meal." %}+ {% trans "Add one now."%}+ </a>+ </td>+</tr>+ {% endfor %}{% empty %}<p>@@ -126,7 +136,7 @@ $(document).ready(function() {</p>{% endfor %}<tr>- <td colspan="2">+ <td colspan="6"><a href="{% url 'meal-add' plan.id %}"class="modal-dialog"><img src="{% static 'images/icons/edit.svg' %}"diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.pyindex e53d1a5b7..8ea813cb6 100644--- a/wger/nutrition/views/plan.py+++ b/wger/nutrition/views/plan.py@@ -120,8 +120,6 @@ def view(request, id):template_data['MEALITEM_WEIGHT_UNIT'] = MEALITEM_WEIGHT_UNIT# Get the nutritional info- import pprint- pprint.pprint(plan.get_nutritional_values())template_data['nutritional_data'] = plan.get_nutritional_values()return render_to_response('plan/view.html',