Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Added appropriate labels based on units to BMI calculator on page render.

koenbf7eda05b758b
diff --git a/wger/nutrition/forms.py b/wger/nutrition/forms.py
index 6252599cd..aac1e42dd 100644
--- a/wger/nutrition/forms.py
+++ b/wger/nutrition/forms.py
@@ -97,7 +97,6 @@ class BmiForm(forms.ModelForm):
height = forms.DecimalField(
widget=Html5NumberInput(),
max_value=999,
- label=_('Height (cm)'),
)
weight = forms.DecimalField(
widget=Html5NumberInput(),
@@ -110,6 +109,10 @@ class BmiForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(BmiForm, self).__init__(*args, **kwargs)
+
+ if 'initial' in kwargs: #if the form is rendering for the first time
+ self['height'].label = 'Height (cm)' if kwargs['initial']['use_metric'] else 'Height (in)'
+ self['weight'].label = 'Weight (kg)' if kwargs['initial']['use_metric'] else 'Weight (lbs)'
self.helper = FormHelper()
self.helper.form_action = reverse('nutrition:bmi:calculate')
diff --git a/wger/nutrition/views/bmi.py b/wger/nutrition/views/bmi.py
index 480c7566e..dabe66da7 100644
--- a/wger/nutrition/views/bmi.py
+++ b/wger/nutrition/views/bmi.py
@@ -47,7 +47,8 @@ def view(request):
context = {}
form_data = {
'height': request.user.userprofile.height,
- 'weight': request.user.userprofile.weight
+ 'weight': request.user.userprofile.weight,
+ 'use_metric' : request.user.userprofile.use_metric
}
context['form'] = BmiForm(initial=form_data)
return render(request, 'bmi/form.html', context)