Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fix handling of decimal values, this is needed for python 2.6

Roland Geiderf931b9111e3d
diff --git a/wger/nutrition/models.py b/wger/nutrition/models.py
index 8607e9718..3f1b85a44 100644
--- a/wger/nutrition/models.py
+++ b/wger/nutrition/models.py
@@ -229,8 +229,8 @@ class Ingredient(models.Model):
(self.fat * 9))
# Compare the values, but be generous
- energy_upper = self.energy * (1 + (self.ENERGY_APPROXIMATION/100.0))
- energy_lower = self.energy * (1 - (self.ENERGY_APPROXIMATION/100.0))
+ energy_upper = self.energy * (1 + (self.ENERGY_APPROXIMATION/decimal.Decimal('100.0')))
+ energy_lower = self.energy * (1 - (self.ENERGY_APPROXIMATION/decimal.Decimal('100.0')))
#logger.debug("{0} > {1} > {2}".format(energy_upper, energy_calculated, energy_lower))
if not ((energy_upper > energy_calculated) and (energy_calculated > energy_lower)):
diff --git a/wger/nutrition/tests/ingredient.py b/wger/nutrition/tests/ingredient.py
index f34051ce2..296cd2767 100644
--- a/wger/nutrition/tests/ingredient.py
+++ b/wger/nutrition/tests/ingredient.py
@@ -362,9 +362,9 @@ class IngredientTestCase(WorkoutManagerTestCase):
ingredient = Ingredient()
ingredient.name = 'FooBar, cooked, with salt'
ingredient.energy = 50
- ingredient.protein = 0.5
+ ingredient.protein = '0.5'
ingredient.carbohydrates = 12
- ingredient.fat = 0.1
+ ingredient.fat = '0.1'
ingredient.language_id = 1
self.assertFalse(ingredient.full_clean())
@@ -372,11 +372,11 @@ class IngredientTestCase(WorkoutManagerTestCase):
ingredient.protein = 20
self.assertRaises(ValidationError, ingredient.full_clean)
- ingredient.protein = 0.5
+ ingredient.protein = '0.5'
ingredient.fat = 5
self.assertRaises(ValidationError, ingredient.full_clean)
- ingredient.fat = 0.1
+ ingredient.fat = '0.1'
ingredient.carbohydrates = 20
self.assertRaises(ValidationError, ingredient.full_clean)