Self hosted FLOSS fitness/workout, nutrition and weight tracker
Label nutrition macros on the gym member page with grams
Roland Geiderc3f256e31fe0
diff --git a/wger/core/templates/user/overview.html b/wger/core/templates/user/overview.htmlindex 97bd270d4..d1a6308a7 100644--- a/wger/core/templates/user/overview.html+++ b/wger/core/templates/user/overview.html@@ -192,13 +192,13 @@{{nutrition_plan.get_nutritional_values.total.energy|floatformat}} {% translate "kcal" %}</td><td>- {{nutrition_plan.get_nutritional_values.total.protein|floatformat}} {% trans_weight_unit 'g' current_user %}+ {{nutrition_plan.get_nutritional_values.total.protein|floatformat}} {% translate "g" context "weight unit, i.e. grams" %}</td><td>- {{nutrition_plan.get_nutritional_values.total.carbohydrates|floatformat}} {% trans_weight_unit 'g' current_user %}+ {{nutrition_plan.get_nutritional_values.total.carbohydrates|floatformat}} {% translate "g" context "weight unit, i.e. grams" %}</td><td>- {{nutrition_plan.get_nutritional_values.total.fat|floatformat}} {% trans_weight_unit 'g' current_user %}+ {{nutrition_plan.get_nutritional_values.total.fat|floatformat}} {% translate "g" context "weight unit, i.e. grams" %}</td></tr>{% empty %}diff --git a/wger/core/templatetags/wger_extras.py b/wger/core/templatetags/wger_extras.pyindex aa7361b6b..26b6c01c4 100644--- a/wger/core/templatetags/wger_extras.py+++ b/wger/core/templatetags/wger_extras.py@@ -21,10 +21,7 @@ from functools import lru_cachefrom django import templatefrom django.contrib.staticfiles.storage import staticfiles_storagefrom django.utils.safestring import mark_safe-from django.utils.translation import (- gettext_lazy as _,- pgettext,-)+from django.utils.translation import gettext_lazy as _# wgerfrom wger.core.tests.base_testcase import get_reverse@@ -98,21 +95,15 @@ def trans_weight_unit(unit, user=None):"""Returns the correct (translated) weight unit- :param unit: the weight unit. Allowed values are 'kg' and 'g'+ :param unit: the weight unit. The only allowed value is 'kg':param user: the user object, needed to access the profile. If this evaluatesto False, metric is used:return: translated unit"""- if not user or user.userprofile.use_metric:- if unit == 'kg':+ if unit == 'kg':+ if not user or user.userprofile.use_metric:return _('kg')- if unit == 'g':- return pgettext('weight unit, i.e. grams', 'g')- else:- if unit == 'kg':- return _('lb')- if unit == 'g':- return pgettext('weight unit, i.e. ounces', 'oz')+ return _('lb')@register.filterdiff --git a/wger/core/tests/test_user.py b/wger/core/tests/test_user.pyindex f8cecf229..ef061e3e5 100644--- a/wger/core/tests/test_user.py+++ b/wger/core/tests/test_user.py@@ -32,6 +32,7 @@ from wger.core.tests.base_testcase import (WgerEditTestCase,WgerTestCase,)+from wger.nutrition.models import NutritionPlanclass StatusUserTestCase(WgerTestCase):@@ -361,6 +362,27 @@ class UserDetailPageTestCase2(WgerAccessTestCase):)+class UserDetailPageMacroUnitTestCase(WgerTestCase):+ """+ Tests that nutrition plan macros on the user detail page are labeled in grams+ """++ def test_macros_labeled_in_grams_for_imperial_user(self):+ """+ Tests that the macro labels stay 'g' for users with imperial units+ """+ member = User.objects.get(pk=2)+ member.userprofile.weight_unit = 'lb'+ member.userprofile.save()+ NutritionPlan.objects.create(user=member)++ self.user_login('trainer1')+ response = self.client.get(reverse('core:user:overview', kwargs={'pk': member.pk}))++ self.assertEqual(response.status_code, 200)+ self.assertNotContains(response, 'oz')++class UserTrustworthinessTestCase(WgerTestCase):request = HttpRequest()