Self hosted FLOSS fitness/workout, nutrition and weight tracker
Nutrition plan view now displays weight entry used. Reverted changes to nutrition entry model.
purplebird0bc5ef96b318
diff --git a/wger/nutrition/models.py b/wger/nutrition/models.pyindex 0363308ef..1c621df32 100644--- a/wger/nutrition/models.py+++ b/wger/nutrition/models.py@@ -103,14 +103,12 @@ class NutritionPlan(models.Model):'''return reverse('nutrition:plan:view', kwargs={'id': self.id})- def get_nutritional_values(self, weight=None):+ def get_nutritional_values(self):'''Sums the nutritional info of all items in the plan'''use_metric = self.user.userprofile.use_metricunit = 'kg' if use_metric else 'lb'- if weight is None:- weight = self.user.userprofile.weightresult = {'total': {'energy': 0,'protein': 0,'carbohydrates': 0,@@ -142,9 +140,10 @@ class NutritionPlan(models.Model):result['total'][key] * ENERGY_FACTOR[key][unit] / energy * 100# Per body weight- if weight > 0:+ weight_entry = self.get_closest_weight_entry()+ if weight_entry:for key in result['per_kg'].keys():- result['per_kg'][key] = result['total'][key] / weight+ result['per_kg'][key] = result['total'][key] / weight_entry.weight# Only 2 decimal places, anything else doesn't make sensefor key in result.keys():diff --git a/wger/nutrition/templates/plan/view.html b/wger/nutrition/templates/plan/view.htmlindex fd89ecb67..b52470195 100644--- a/wger/nutrition/templates/plan/view.html+++ b/wger/nutrition/templates/plan/view.html@@ -184,10 +184,9 @@ function custom_modal_init()</p>{% endif %}-<h4>{% trans "Nutritional data" %}</h4>-{% if closest_weight_entry %}- {% blocktrans with date=closest_weight_entry.date weight=closest_weight_entry.weight %}+{% if weight_entry %}+ {% blocktrans with date=weight_entry.date weight=weight_entry.weight %}<h5> Based on the weight entry dated {{date}} ({{weight}})</h5>{% endblocktrans %}{% endif %}diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.pyindex b6d26b226..24f41a703 100644--- a/wger/nutrition/views/plan.py+++ b/wger/nutrition/views/plan.py@@ -144,13 +144,11 @@ def view(request, id):# Get the nutritional infotemplate_data['plan'] = plan- closest_weight_entry = plan.get_closest_weight_entry()- template_data['closest_weight_entry'] = closest_weight_entry- if closest_weight_entry is not None:- template_data['nutritional_data'] = \- plan.get_nutritional_values(closest_weight_entry.weight)- else:- template_data['nutritional_data'] = plan.get_nutritional_values()+ template_data['nutritional_data'] = \+ plan.get_nutritional_values()++ # Get the weight entry used+ template_data['weight_entry'] = plan.get_closest_weight_entry()# Tokens for the linkstemplate_data['uid'] = uid