From 4120adc5464074d4cb44a0ac790b2651c3c513c1 Mon Sep 17 00:00:00 2001 From: smilerz Date: Thu, 31 Aug 2023 13:12:41 -0500 Subject: [PATCH] applied regex_replace automation to food and unit automations updated automation documentation --- cookbook/helper/automation_helper.py | 5 ++--- docs/features/automation.md | 8 +++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cookbook/helper/automation_helper.py b/cookbook/helper/automation_helper.py index 67a4b255..442b1c6f 100644 --- a/cookbook/helper/automation_helper.py +++ b/cookbook/helper/automation_helper.py @@ -77,7 +77,7 @@ class AutomationEngine: else: if automation := Automation.objects.filter(space=self.request.space, type=Automation.UNIT_ALIAS, param_1__iexact=unit, disabled=False).order_by('order').first(): return automation.param_2 - return unit + return self.apply_regex_replace_automation(unit, Automation.UNIT_REPLACE) def apply_food_automation(self, food): food = food.strip() @@ -102,7 +102,7 @@ class AutomationEngine: else: if automation := Automation.objects.filter(space=self.request.space, type=Automation.FOOD_ALIAS, param_1__iexact=food, disabled=False).order_by('order').first(): return automation.param_2 - return self.apply_regex_replace_automation(food) + return self.apply_regex_replace_automation(food, Automation.FOOD_REPLACE) def apply_never_unit_automation(self, tokens): """ @@ -189,7 +189,6 @@ class AutomationEngine: field_type are Automation.type that apply regex replacements Automation.DESCRIPTION_REPLACE Automation.INSTRUCTION_REPLACE - # TODO implement these Automation.FOOD_REPLACE Automation.UNIT_REPLACE Automation.TITLE_REPLACE diff --git a/docs/features/automation.md b/docs/features/automation.md index b1965e29..f857a09d 100644 --- a/docs/features/automation.md +++ b/docs/features/automation.md @@ -50,10 +50,12 @@ In order to prevent denial of service attacks on the RegEx engine the number of and the length of the inputs that are processed are limited. Those limits should never be reached during normal usage. -## Instruction Replace +## Instructtion Replace, Title Replace, Food Replace & Unit Replace -This works just like the Description Replace automation but runs against all instruction texts -in all steps of a recipe during import. +These work just like the Description Replace automation. +Instruction, Food and Unit Replace will run against every iteration of the object in a recipe during import. +- Instruction Replace will run for the instructions in every step. It will also replace every occurrence, not just the first. +- Food & Unit Replace will run for every food and unit in every ingredient in every step. Also instead of just replacing a single occurrence of the matched pattern it will replace all.