From bdd092e5d3f3cb785d1ac4a79c4b490f7654c9bb Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Tue, 7 Apr 2020 20:13:20 +0200 Subject: [PATCH] fixed ingredient amount numeric --- cookbook/templates/forms/edit_internal_recipe.html | 3 ++- cookbook/views/edit.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html index b1333b3c0..b64a1ce12 100644 --- a/cookbook/templates/forms/edit_internal_recipe.html +++ b/cookbook/templates/forms/edit_internal_recipe.html @@ -26,6 +26,7 @@ {% if field.name == 'name' %} + {{ form.ingredients.errors }}

@@ -144,7 +145,7 @@ validator: "required", editor: select2IngredientEditor }, - {title: "{% trans 'Amount' %}", field: "amount", validator: "required", editor: "input"}, + {title: "{% trans 'Amount' %}", field: "amount", validator: "required", editor: "number"}, { title: "{% trans 'Unit' %}", field: "unit__name", diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index 989f2c904..b28b5a448 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -98,7 +98,10 @@ def internal_recipe_update(request, pk): recipe_ingredient.ingredient = ingredient if isinstance(i['amount'], str): - recipe_ingredient.amount = float(i['amount'].replace(',', '.')) + try: + recipe_ingredient.amount = float(i['amount'].replace(',', '.')) + except ValueError: + form.add_error("ingredients", _('There was an error converting your ingredients amount to a number: ') + i['unit__name']) else: recipe_ingredient.amount = i['amount']