From 332c4bd94a00314db55251e27084c79233a3d82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Wiedemann?= Date: Tue, 21 Mar 2023 18:04:03 +0100 Subject: [PATCH] add: support to scale numbers/amounts --- cookbook/helper/template_helper.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cookbook/helper/template_helper.py b/cookbook/helper/template_helper.py index 9bde2fc0..eafe24d5 100644 --- a/cookbook/helper/template_helper.py +++ b/cookbook/helper/template_helper.py @@ -15,12 +15,14 @@ class IngredientObject(object): unit = "" food = "" note = "" + numeric_amount = 0 def __init__(self, ingredient): if ingredient.no_amount: self.amount = "" else: self.amount = f"" + self.numeric_amount = float(ingredient.amount) if ingredient.unit: if ingredient.unit.plural_name in (None, ""): self.unit = bleach.clean(str(ingredient.unit)) @@ -72,9 +74,12 @@ def render_instructions(step): # TODO deduplicate markdown cleanup code for i in step.ingredients.all(): ingredients.append(IngredientObject(i)) + def scale(number): + return f"" + try: template = Template(instructions) - instructions = template.render(ingredients=ingredients) + instructions = template.render(ingredients=ingredients, scale=scale) except TemplateSyntaxError: return _('Could not parse template code.') + ' Error: Template Syntax broken' except UndefinedError: