diff --git a/wger/nutrition/models.py b/wger/nutrition/models.py index 644876e6d..0363308ef 100644 --- a/wger/nutrition/models.py +++ b/wger/nutrition/models.py @@ -103,12 +103,14 @@ def get_absolute_url(self): ''' return reverse('nutrition:plan:view', kwargs={'id': self.id}) - def get_nutritional_values(self, weight=0): + def get_nutritional_values(self, weight=None): ''' Sums the nutritional info of all items in the plan ''' use_metric = self.user.userprofile.use_metric unit = 'kg' if use_metric else 'lb' + if weight is None: + weight = self.user.userprofile.weight result = {'total': {'energy': 0, 'protein': 0, 'carbohydrates': 0, diff --git a/wger/nutrition/tests/test_nutritional_calculations.py b/wger/nutrition/tests/test_nutritional_calculations.py index 6bfd77ea8..dfe61d799 100644 --- a/wger/nutrition/tests/test_nutritional_calculations.py +++ b/wger/nutrition/tests/test_nutritional_calculations.py @@ -133,7 +133,7 @@ def test_calculations_user(self): ''' self.user_login('test') plan = models.NutritionPlan.objects.get(pk=4) - values = plan.get_nutritional_values(plan.user.userprofile.weight) + values = plan.get_nutritional_values() self.assertEqual(values['percent']['carbohydrates'], Decimal(29.79).quantize(TWOPLACES)) self.assertEqual(values['percent']['fat'], Decimal(20.36).quantize(TWOPLACES)) diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.py index b54ad6c1b..626066975 100644 --- a/wger/nutrition/views/plan.py +++ b/wger/nutrition/views/plan.py @@ -147,10 +147,11 @@ def view(request, id): closest_weight_entry = plan.get_closest_weight_entry() template_data['closest_weight_entry'] = closest_weight_entry if closest_weight_entry is not None: - weight = closest_weight_entry.weight + template_data['nutritional_data'] = \ + plan.get_nutritional_values(closest_weight_entry.weight) else: - weight = 0 - template_data['nutritional_data'] = plan.get_nutritional_values(weight) + template_data['nutritional_data'] = plan.get_nutritional_values() + # Tokens for the links template_data['uid'] = uid