Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Automatic linting

Github-actions1ed764fbaf1d
diff --git a/wger/core/models/profile.py b/wger/core/models/profile.py
index 26b8b9d7f..ba7ca646f 100644
--- a/wger/core/models/profile.py
+++ b/wger/core/models/profile.py
@@ -33,7 +33,10 @@ from django.utils.translation import gettext_lazy as _
# wger
from wger.gym.models import Gym
from wger.utils.constants import TWOPLACES
-from wger.utils.units import AbstractWeight, AbstractHeight
+from wger.utils.units import (
+ AbstractHeight,
+ AbstractWeight,
+)
from wger.weight.models import WeightEntry
# Local
diff --git a/wger/nutrition/forms.py b/wger/nutrition/forms.py
index 71a84068e..7ae045147 100644
--- a/wger/nutrition/forms.py
+++ b/wger/nutrition/forms.py
@@ -109,10 +109,12 @@ 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)')
+
+ 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/tests/test_bmi.py b/wger/nutrition/tests/test_bmi.py
index 5321b5694..836824f68 100644
--- a/wger/nutrition/tests/test_bmi.py
+++ b/wger/nutrition/tests/test_bmi.py
@@ -81,7 +81,6 @@ class BmiTestCase(WgerTestCase):
response = json.loads(response.content.decode('utf8'))
self.assertTrue('error' in response)
-
def test_calculator_metric_high_height(self):
"""
Tests the calculator when the height is too low. Should trigger an error message.
@@ -100,7 +99,6 @@ class BmiTestCase(WgerTestCase):
response = json.loads(response.content.decode('utf8'))
self.assertTrue('error' in response)
-
def test_calculator_imperial(self):
"""
Tests the calculator using imperial units
@@ -141,7 +139,6 @@ class BmiTestCase(WgerTestCase):
response = json.loads(response.content.decode('utf8'))
self.assertTrue('error' in response)
-
def test_calculator_imperial_high_height(self):
"""
Tests the calculator when the height is too low. Should trigger an error message.
diff --git a/wger/nutrition/views/bmi.py b/wger/nutrition/views/bmi.py
index 8651a0d4c..582fff185 100644
--- a/wger/nutrition/views/bmi.py
+++ b/wger/nutrition/views/bmi.py
@@ -23,14 +23,12 @@ import logging
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.shortcuts import render
+from django.utils.translation import gettext as _
# wger
from wger.nutrition.forms import BmiForm
from wger.utils import helpers
from wger.utils.units import AbstractHeight
-from django.utils.translation import gettext as _
-
-
logger = logging.getLogger(__name__)
@@ -49,7 +47,7 @@ def view(request):
form_data = {
'height': request.user.userprofile.height,
'weight': request.user.userprofile.weight,
- 'use_metric' : request.user.userprofile.use_metric
+ 'use_metric': request.user.userprofile.use_metric
}
context['form'] = BmiForm(initial=form_data)
return render(request, 'bmi/form.html', context)
@@ -65,7 +63,7 @@ def calculate(request):
form = BmiForm(request.POST, instance=request.user.userprofile)
output_height = request.POST['height']
-
+
if not request.user.userprofile.use_metric:
request_copy = request.POST.copy()
output_height = request_copy['height']
@@ -99,7 +97,6 @@ def calculate(request):
response.status_code = 406
# Return the results to the client
return response
-
def chart_data(request):
diff --git a/wger/utils/units.py b/wger/utils/units.py
index e6bfef28c..b0da5e8a3 100644
--- a/wger/utils/units.py
+++ b/wger/utils/units.py
@@ -116,6 +116,7 @@ class AbstractWeight(object):
"""
return self.normalize(self.lb * 16)
+
class AbstractHeight(object):
"""
Helper class to use when working with sensible (cm) or imperial units.
@@ -163,7 +164,6 @@ class AbstractHeight(object):
else:
return self.normalize(self.height * self.INCHES_IN_CM)
-
@property
def inches(self):
"""