translated, documented and implemented instruction replace
This commit is contained in:
parent
6176eeb024
commit
798457e7e2
@ -185,10 +185,11 @@ def get_from_scraper(scrape, request):
|
||||
pass
|
||||
|
||||
if recipe_json['source_url']:
|
||||
automations = Automation.objects.filter(type=Automation.DESCRIPTION_REPLACE, space=request.space, disabled=False).only('param_1', 'param_2', 'param_3').order_by('order').all()[:512]
|
||||
automations = Automation.objects.filter(type=Automation.INSTRUCTION_REPLACE, space=request.space, disabled=False).only('param_1', 'param_2', 'param_3').order_by('order').all()[:512]
|
||||
for a in automations:
|
||||
if re.match(a.param_1, (recipe_json['source_url'])[:512]):
|
||||
recipe_json['description'] = re.sub(a.param_2, a.param_3, recipe_json['description'], count=1)
|
||||
for s in recipe_json['steps']:
|
||||
s['instruction'] = re.sub(a.param_2, a.param_3, s['instruction'])
|
||||
|
||||
return recipe_json
|
||||
|
||||
|
@ -101,6 +101,7 @@ def page_help(page_name):
|
||||
'view_shopping': 'https://docs.tandoor.dev/features/shopping/',
|
||||
'view_import': 'https://docs.tandoor.dev/features/import_export/',
|
||||
'view_export': 'https://docs.tandoor.dev/features/import_export/',
|
||||
'list_automation': 'https://docs.tandoor.dev/features/automation/',
|
||||
}
|
||||
|
||||
link = help_pages.get(page_name, '')
|
||||
|
@ -7,12 +7,26 @@
|
||||
Automations allow Tandoor to automatically perform certain tasks, especially when importing recipes, that
|
||||
would otherwise have to be done manually. Currently, the following automations are supported.
|
||||
|
||||
|
||||
## Unit, Food, Keyword Alias
|
||||
asd
|
||||
Foods, Units and Keywords can have automations that automatically replace them with another object
|
||||
to allow aliasing them.
|
||||
|
||||
This helps to add consistency to the naming of objects, for example to always use the singular form
|
||||
for the main name if a plural form is configured.
|
||||
|
||||
These automations are best created by dragging and dropping Foods, Units or Keywords in their respective
|
||||
views and creating the automation there.
|
||||
|
||||
You can also create them manually by setting the following
|
||||
- **Parameter 1**: name of food/unit/keyword to match
|
||||
- **Parameter 2**: name of food/unit/keyword to replace matched food with
|
||||
|
||||
These rules are processed whenever you are importing recipes from websites or other apps
|
||||
and when using the simple ingredient input (shopping, recipe editor, ...).
|
||||
|
||||
## Description Replace
|
||||
This automation is a bit more complicated than the alis rules.
|
||||
This automation is a bit more complicated than the alis rules. It is run when importing a recipe
|
||||
from a website.
|
||||
|
||||
It uses Regular Expressions (RegEx) to determine if a description should be altered, what exactly to remove
|
||||
and what to replace it with.
|
||||
@ -26,6 +40,17 @@ like this `re.sub(<parameter 2>, <parameter 2>, <descriotion>, count=1)`
|
||||
|
||||
To test out your patterns and learn about RegEx you can use [regexr.com](https://regexr.com/)
|
||||
|
||||
!!! info
|
||||
In order to prevent denial of service attacks on the RegEx engine the number of replace automations
|
||||
and the length of the inputs that are processed are limited. Those limits should never be reached
|
||||
during normal usage.
|
||||
|
||||
## Instruction Replace
|
||||
This works just like the Description Replace automation but runs against all instruction texts
|
||||
in all steps of a recipe during import.
|
||||
|
||||
Also instead of just replacing a single occurrence of the matched pattern it will replace all.
|
||||
|
||||
# Order
|
||||
If the Automation type allows for more than one rule to be executed (for example description replace)
|
||||
the rules are processed in ascending order (ordered by the *order* property of the automation).
|
||||
|
@ -68,6 +68,8 @@
|
||||
"Enable_Amount": "Enable Amount",
|
||||
"Disable_Amount": "Disable Amount",
|
||||
"Ingredient Editor": "Ingredient Editor",
|
||||
"Description_Replace": "Description Replace",
|
||||
"Instruction_Replace": "Instruction Replace",
|
||||
"Auto_Sort": "Auto Sort",
|
||||
"Auto_Sort_Help": "Move all ingredients to the best fitting step.",
|
||||
"Private_Recipe": "Private Recipe",
|
||||
|
Loading…
Reference in New Issue
Block a user