Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

implement feedback

Luca van der Wijngaart02fcaa3c884e
diff --git a/wger/nutrition/api/views.py b/wger/nutrition/api/views.py
index 15e11fc2a..7b7028dc9 100644
--- a/wger/nutrition/api/views.py
+++ b/wger/nutrition/api/views.py
@@ -89,14 +89,6 @@ class IngredientViewSet(viewsets.ReadOnlyModelViewSet):
'license',
).prefetch_related('ingredientweightunit_set__unit')
- def get_object(self):
- """
- Opportunistically sync OFF serving units for accessed ingredients.
- """
- ingredient = super().get_object()
- ingredient.sync_serving_unit_from_off_if_missing()
- return ingredient
-
@method_decorator(cache_page(settings.WGER_SETTINGS['INGREDIENT_CACHE_TTL']))
def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)
diff --git a/wger/nutrition/models/ingredient.py b/wger/nutrition/models/ingredient.py
index d679c3448..fc2ab6e07 100644
--- a/wger/nutrition/models/ingredient.py
+++ b/wger/nutrition/models/ingredient.py
@@ -466,6 +466,11 @@ class Ingredient(AbstractLicenseModel, models.Model):
fetch_ingredient_image_task.delay(self.pk)
def update_or_create_serving_unit_from_off(self, ingredient_data):
+ """
+ Fetch serving size from OFF and update or create a record of it.
+
+ Returns (boolean, boolean). First boolean is whether serving unit was created, second boolean whether it was updated.
+ """
if not ingredient_data.serving_size_unit:
return (False, False)
@@ -515,7 +520,7 @@ class Ingredient(AbstractLicenseModel, models.Model):
gram=gram,
amount=amount,
)
- return (True, False) # (created, updated)
+ return (True, False) # (created, updated)
@staticmethod
def _derive_serving_size_gram(amount, unit):
diff --git a/wger/nutrition/views/ingredient.py b/wger/nutrition/views/ingredient.py
index 6c1eb34a4..cbe318ec3 100644
--- a/wger/nutrition/views/ingredient.py
+++ b/wger/nutrition/views/ingredient.py
@@ -100,9 +100,6 @@ def view(request, pk, slug=None):
settings.WGER_SETTINGS['INGREDIENT_CACHE_TTL'],
)
- # Opportunistically fetch missing OFF serving units during page load.
- ingredient.sync_serving_unit_from_off_if_missing()
-
context['ingredient'] = ingredient
context['image'] = ingredient.get_image(request)
context['form'] = UnitChooserForm(