Skip to content

Commit

Permalink
fibre/fibres/fibers -> fiber
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed May 21, 2024
1 parent 3c4ca16 commit 6ce1513
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 43 deletions.
2 changes: 1 addition & 1 deletion wger/nutrition/api/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Meta:
'energy': ['exact'],
'fat': ['exact'],
'fat_saturated': ['exact'],
'fibres': ['exact'],
'fiber': ['exact'],
'name': ['exact'],
'protein': ['exact'],
'sodium': ['exact'],
Expand Down
8 changes: 4 additions & 4 deletions wger/nutrition/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Meta:
'carbohydrates_sugar',
'fat',
'fat_saturated',
'fibres',
'fiber',
'sodium',
'license',
'license_title',
Expand Down Expand Up @@ -160,7 +160,7 @@ class Meta:
'carbohydrates_sugar',
'fat',
'fat_saturated',
'fibres',
'fiber',
'sodium',
'weight_units',
'language',
Expand Down Expand Up @@ -265,7 +265,7 @@ class NutritionalValuesSerializer(serializers.Serializer):
carbohydrates_sugar = serializers.FloatField()
fat = serializers.FloatField()
fat_saturated = serializers.FloatField()
fibres = serializers.FloatField()
fiber = serializers.FloatField()
sodium = serializers.FloatField()


Expand Down Expand Up @@ -312,7 +312,7 @@ class Meta:
'goal_protein',
'goal_carbohydrates',
'goal_fat',
'goal_fibers',
'goal_fiber',
# 'nutritional_values',
]

Expand Down
2 changes: 1 addition & 1 deletion wger/nutrition/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def get_values(self, request, pk):
'carbohydrates_sugar': 0,
'fat': 0,
'fat_saturated': 0,
'fibres': 0,
'fiber': 0,
'sodium': 0,
'errors': [],
}
Expand Down
4 changes: 2 additions & 2 deletions wger/nutrition/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class Meta:
'carbohydrates_sugar',
'fat',
'fat_saturated',
'fibres',
'fiber',
'sodium',
'license',
'license_author',
Expand Down Expand Up @@ -371,7 +371,7 @@ def __init__(self, *args, **kwargs):
Column('fat_saturated', css_class='col-6'),
css_class='form-row',
),
'fibres',
'fiber',
'sodium',
Row(
Column('license', css_class='col-6'),
Expand Down
12 changes: 6 additions & 6 deletions wger/nutrition/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def get_nutritional_values(self, use_metric=True):
if self.ingredient.fat_saturated:
values.fat_saturated = self.ingredient.fat_saturated * item_weight / 100

if self.ingredient.fibres:
values.fibres = self.ingredient.fibres * item_weight / 100
if self.ingredient.fiber:
values.fiber = self.ingredient.fiber * item_weight / 100

if self.ingredient.sodium:
values.sodium = self.ingredient.sodium * item_weight / 100
Expand Down Expand Up @@ -110,7 +110,7 @@ class NutritionalValues:
carbohydrates_sugar: Union[Decimal, int, float, None] = None
fat: Union[Decimal, int, float] = 0
fat_saturated: Union[Decimal, int, float, None] = None
fibres: Union[Decimal, int, float, None] = None
fiber: Union[Decimal, int, float, None] = None
sodium: Union[Decimal, int, float, None] = None

@property
Expand All @@ -132,9 +132,9 @@ def __add__(self, other: 'NutritionalValues'):
fat_saturated=self.fat_saturated + other.fat_saturated
if self.fat_saturated and other.fat_saturated
else self.fat_saturated or other.fat_saturated,
fibres=self.fibres + other.fibres
if self.fibres and other.fibres
else self.fibres or other.fibres,
fiber=self.fiber + other.fiber
if self.fiber and other.fiber
else self.fiber or other.fiber,
sodium=self.sodium + other.sodium
if self.sodium and other.sodium
else self.sodium or other.sodium,
Expand Down
23 changes: 23 additions & 0 deletions wger/nutrition/migrations/0022_fiber_spelling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.6 on 2024-05-21 19:32

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nutrition', '0021_add_fibers_field'),
]

operations = [
migrations.RemoveField(
model_name='ingredient',
name='fibres',
),
migrations.AddField(
model_name='ingredient',
name='fiber',
field=models.DecimalField(blank=True, decimal_places=3, help_text='In g per 100g of product', max_digits=6, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(100)], verbose_name='Fiber'),
),
]
6 changes: 3 additions & 3 deletions wger/nutrition/models/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ class Ingredient(AbstractSubmissionModel, AbstractLicenseModel, models.Model):
validators=[MinValueValidator(0), MaxValueValidator(100)],
)

fibres = models.DecimalField(
fiber = models.DecimalField(
decimal_places=3,
max_digits=6,
blank=True,
null=True,
verbose_name=_('Fibres'),
verbose_name=_('Fiber'),
help_text=_('In g per 100g of product'),
validators=[MinValueValidator(0), MaxValueValidator(100)],
)
Expand Down Expand Up @@ -339,7 +339,7 @@ def __eq__(self, other):
'energy',
'fat',
'fat_saturated',
'fibres',
'fiber',
'name',
'protein',
'sodium',
Expand Down
6 changes: 3 additions & 3 deletions wger/nutrition/off.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class IngredientData:
carbohydrates_sugar: float
fat: float
fat_saturated: float
fibres: Optional[float]
fiber: Optional[float]
sodium: Optional[float]
code: str
source_name: str
Expand Down Expand Up @@ -101,7 +101,7 @@ def extract_info_from_off(product_data, language: int):

# these are optional
sodium = product_data['nutriments'].get('sodium_100g', None)
fibre = product_data['nutriments'].get('fiber_100g', None)
fiber = product_data['nutriments'].get('fiber_100g', None)
brand = product_data.get('brands', None)

# License and author info
Expand All @@ -119,7 +119,7 @@ def extract_info_from_off(product_data, language: int):
carbohydrates_sugar=sugars,
fat=fat,
fat_saturated=saturated,
fibres=fibre,
fiber=fiber,
sodium=sodium,
code=code,
source_name=source_name,
Expand Down
2 changes: 1 addition & 1 deletion wger/nutrition/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def sync_ingredients(
'fat': data['fat'],
'fat_saturated': data['fat_saturated'],
'protein': data['protein'],
'fibres': data['fibres'],
'fiber': data['fiber'],
'sodium': data['sodium'],
},
)
Expand Down
6 changes: 3 additions & 3 deletions wger/nutrition/templates/ingredient/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ <h4>{% translate "Ingredient is pending review" %}</h4>
</thead>
<tbody>
<tr>
<td>{% translate "Fibres" %}</td>
<td>{% translate "Fiber" %}</td>
<td itemprop="fiberContent" class="text-right">
{% if ingredient.fibres %}
<span id="value-fibres">{{ingredient.fibres|floatformat:1}}</span> {% translate "g" context "weight unit, i.e. grams" %}
{% if ingredient.fiber %}
<span id="value-fiber">{{ingredient.fiber|floatformat:1}}</span> {% translate "g" context "weight unit, i.e. grams" %}
{% else %}
{% translate "n.A." %}
{% endif %}
Expand Down
12 changes: 6 additions & 6 deletions wger/nutrition/tests/test_ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class EditIngredientTestCase(WgerEditTestCase):
'fat': 10,
'carbohydrates_sugar': 5,
'fat_saturated': 3.14,
'fibres': 2.1,
'fiber': 2.1,
'protein': 20,
'carbohydrates': 10,
'license': 2,
Expand Down Expand Up @@ -119,7 +119,7 @@ class AddIngredientTestCase(WgerAddTestCase):
'fat': 10,
'carbohydrates_sugar': 5,
'fat_saturated': 3.14,
'fibres': 2.1,
'fiber': 2.1,
'protein': 20,
'carbohydrates': 10,
'license': 2,
Expand Down Expand Up @@ -154,7 +154,7 @@ class IngredientNameShortTestCase(WgerTestCase):
'fat': 10,
'carbohydrates_sugar': 5,
'fat_saturated': 3.14,
'fibres': 2.1,
'fiber': 2.1,
'protein': 20,
'carbohydrates': 10,
'license': 2,
Expand Down Expand Up @@ -324,7 +324,7 @@ def calculate_value(self):
'fat': 0.0819,
'carbohydrates_sugar': None,
'fat_saturated': 0.03244,
'fibres': None,
'fiber': None,
'protein': 0.2563,
'carbohydrates': 0.00125,
},
Expand All @@ -348,7 +348,7 @@ def calculate_value(self):
'fat': 9.13185,
'carbohydrates_sugar': None,
'fat_saturated': 3.61706,
'fibres': None,
'fiber': None,
'protein': 28.57745,
'carbohydrates': 0.139375,
},
Expand Down Expand Up @@ -506,7 +506,7 @@ def test_fetch_from_off_success(self, mock_api):
self.assertEqual(ingredient.fat, 40)
self.assertEqual(ingredient.fat_saturated, 11)
self.assertEqual(ingredient.sodium, 5)
self.assertEqual(ingredient.fibres, None)
self.assertEqual(ingredient.fiber, None)
self.assertEqual(ingredient.brand, 'The bar company')
self.assertEqual(ingredient.license_author, 'open food facts, MrX')

Expand Down
2 changes: 1 addition & 1 deletion wger/nutrition/tests/test_ingredient_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_overview(self):
'fat': 8.19,
'carbohydrates_sugar': 0.0,
'fat_saturated': 3.24,
'fibres': 0.0,
'fiber': 0.0,
'protein': 25.63,
'carbohydrates': 0.0,
'license': 1,
Expand Down
2 changes: 1 addition & 1 deletion wger/nutrition/tests/test_nutritional_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_calculations(self):
self.assertAlmostEqual(item_values.fat, ingredient.fat, 2)
self.assertAlmostEqual(item_values.fat_saturated, ingredient.fat_saturated, 2)
self.assertAlmostEqual(item_values.sodium, ingredient.sodium, 2)
self.assertAlmostEqual(item_values.fibres, None, 2)
self.assertAlmostEqual(item_values.fiber, None, 2)

meal_nutritional_values = meal.get_nutritional_values()
self.assertEqual(item_values, meal_nutritional_values)
Expand Down
10 changes: 5 additions & 5 deletions wger/nutrition/tests/test_nutritional_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_addition(self):
carbohydrates_sugar=70,
fat=60,
fat_saturated=50,
fibres=40,
fiber=40,
sodium=30,
)
values2 = NutritionalValues(
Expand All @@ -50,7 +50,7 @@ def test_addition(self):
carbohydrates_sugar=7,
fat=6,
fat_saturated=5,
fibres=4,
fiber=4,
sodium=3,
)
values3 = values1 + values2
Expand All @@ -64,7 +64,7 @@ def test_addition(self):
carbohydrates_sugar=77,
fat=66,
fat_saturated=55,
fibres=44,
fiber=44,
sodium=33,
),
)
Expand All @@ -73,7 +73,7 @@ def test_addition_nullable_values(self):
"""Test that the addition works correctly for the nullable values"""

values1 = NutritionalValues()
values2 = NutritionalValues(carbohydrates_sugar=10, fat_saturated=20, fibres=30, sodium=40)
values2 = NutritionalValues(carbohydrates_sugar=10, fat_saturated=20, fiber=30, sodium=40)
values3 = values1 + values2

self.assertEqual(
Expand All @@ -85,7 +85,7 @@ def test_addition_nullable_values(self):
carbohydrates_sugar=10,
fat=0,
fat_saturated=20,
fibres=30,
fiber=30,
sodium=40,
),
)
2 changes: 1 addition & 1 deletion wger/nutrition/tests/test_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_regular_response(self):
carbohydrates_sugar=30,
fat=40,
fat_saturated=11,
fibres=None,
fiber=None,
sodium=5,
code='1234',
source_name='Open Food Facts',
Expand Down
4 changes: 2 additions & 2 deletions wger/nutrition/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def json():
"carbohydrates_sugar": "27.000",
"fat": "18.000",
"fat_saturated": "4.500",
"fibres": "2.000",
"fiber": "2.000",
"sodium": "0.356",
"license": 5,
"license_title": " Gâteau double chocolat ",
Expand All @@ -73,7 +73,7 @@ def json():
"carbohydrates_sugar": "5.600",
"fat": "11.000",
"fat_saturated": "4.600",
"fibres": None,
"fiber": None,
"sodium": "0.820",
"license": 5,
"license_title": " Maxi Hot Dog New York Style",
Expand Down
6 changes: 3 additions & 3 deletions wger/nutrition/views/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ def export_pdf(request, id: int):
)
data.append(
[
Paragraph(_('Fibres'), styleSheet['Normal']),
Paragraph(str(plan_data['total'].fibres), styleSheet['Normal']),
Paragraph(_('Fiber'), styleSheet['Normal']),
Paragraph(str(plan_data['total'].fiber), styleSheet['Normal']),
]
)
data.append(
Expand All @@ -299,7 +299,7 @@ def export_pdf(request, id: int):
table_style.append(('BACKGROUND', (0, 6), (-1, 6), row_color)) # Fats
table_style.append(('SPAN', (1, 7), (-1, 7))) # Saturated fats
table_style.append(('LEFTPADDING', (0, 7), (0, 7), 15))
table_style.append(('SPAN', (1, 8), (-1, 8))) # Fibres
table_style.append(('SPAN', (1, 8), (-1, 8))) # Fiber
table_style.append(('SPAN', (1, 9), (-1, 9))) # Sodium
t = Table(data, style=table_style)
t._argW[0] = 6 * cm
Expand Down

0 comments on commit 6ce1513

Please sign in to comment.