paprika improvements and importer fixes
This commit is contained in:
@ -44,12 +44,13 @@ class Pepperplate(Integration):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for ingredient in ingredients:
|
for ingredient in ingredients:
|
||||||
amount, unit, ingredient, note = parse(ingredient)
|
if len(ingredient.strip()) > 0:
|
||||||
f = get_food(ingredient, self.request.space)
|
amount, unit, ingredient, note = parse(ingredient)
|
||||||
u = get_unit(unit, self.request.space)
|
f = get_food(ingredient, self.request.space)
|
||||||
step.ingredients.add(Ingredient.objects.create(
|
u = get_unit(unit, self.request.space)
|
||||||
food=f, unit=u, amount=amount, note=note
|
step.ingredients.add(Ingredient.objects.create(
|
||||||
))
|
food=f, unit=u, amount=amount, note=note
|
||||||
|
))
|
||||||
recipe.steps.add(step)
|
recipe.steps.add(step)
|
||||||
|
|
||||||
return recipe
|
return recipe
|
||||||
|
@ -45,12 +45,13 @@ class ChefTap(Integration):
|
|||||||
step.save()
|
step.save()
|
||||||
|
|
||||||
for ingredient in ingredients:
|
for ingredient in ingredients:
|
||||||
amount, unit, ingredient, note = parse(ingredient)
|
if len(ingredient.strip()) > 0:
|
||||||
f = get_food(ingredient, self.request.space)
|
amount, unit, ingredient, note = parse(ingredient)
|
||||||
u = get_unit(unit, self.request.space)
|
f = get_food(ingredient, self.request.space)
|
||||||
step.ingredients.add(Ingredient.objects.create(
|
u = get_unit(unit, self.request.space)
|
||||||
food=f, unit=u, amount=amount, note=note
|
step.ingredients.add(Ingredient.objects.create(
|
||||||
))
|
food=f, unit=u, amount=amount, note=note
|
||||||
|
))
|
||||||
recipe.steps.add(step)
|
recipe.steps.add(step)
|
||||||
|
|
||||||
return recipe
|
return recipe
|
||||||
|
@ -35,12 +35,13 @@ class Domestica(Integration):
|
|||||||
step.instruction += '\n' + file['source']
|
step.instruction += '\n' + file['source']
|
||||||
|
|
||||||
for ingredient in file['ingredients'].split('\n'):
|
for ingredient in file['ingredients'].split('\n'):
|
||||||
amount, unit, ingredient, note = parse(ingredient)
|
if len(ingredient.strip()) > 0:
|
||||||
f = get_food(ingredient, self.request.space)
|
amount, unit, ingredient, note = parse(ingredient)
|
||||||
u = get_unit(unit, self.request.space)
|
f = get_food(ingredient, self.request.space)
|
||||||
step.ingredients.add(Ingredient.objects.create(
|
u = get_unit(unit, self.request.space)
|
||||||
food=f, unit=u, amount=amount, note=note
|
step.ingredients.add(Ingredient.objects.create(
|
||||||
))
|
food=f, unit=u, amount=amount, note=note
|
||||||
|
))
|
||||||
recipe.steps.add(step)
|
recipe.steps.add(step)
|
||||||
|
|
||||||
if file['image'] != '':
|
if file['image'] != '':
|
||||||
|
@ -48,12 +48,13 @@ class MealMaster(Integration):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for ingredient in ingredients:
|
for ingredient in ingredients:
|
||||||
amount, unit, ingredient, note = parse(ingredient)
|
if len(ingredient.strip()) > 0:
|
||||||
f = get_food(ingredient, self.request.space)
|
amount, unit, ingredient, note = parse(ingredient)
|
||||||
u = get_unit(unit, self.request.space)
|
f = get_food(ingredient, self.request.space)
|
||||||
step.ingredients.add(Ingredient.objects.create(
|
u = get_unit(unit, self.request.space)
|
||||||
food=f, unit=u, amount=amount, note=note
|
step.ingredients.add(Ingredient.objects.create(
|
||||||
))
|
food=f, unit=u, amount=amount, note=note
|
||||||
|
))
|
||||||
recipe.steps.add(step)
|
recipe.steps.add(step)
|
||||||
|
|
||||||
return recipe
|
return recipe
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import base64
|
import base64
|
||||||
import gzip
|
import gzip
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
from cookbook.helper.ingredient_parser import parse, get_food, get_unit
|
||||||
from cookbook.integration.integration import Integration
|
from cookbook.integration.integration import Integration
|
||||||
from cookbook.models import Recipe, Step, Ingredient
|
from cookbook.models import Recipe, Step, Ingredient, Keyword
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
|
|
||||||
class Paprika(Integration):
|
class Paprika(Integration):
|
||||||
@ -21,17 +23,49 @@ class Paprika(Integration):
|
|||||||
name=recipe_json['name'].strip(), description=recipe_json['description'].strip(),
|
name=recipe_json['name'].strip(), description=recipe_json['description'].strip(),
|
||||||
created_by=self.request.user, internal=True, space=self.request.space)
|
created_by=self.request.user, internal=True, space=self.request.space)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if re.match(r'([0-9])+\s(.)*', recipe_json['servings'] ):
|
||||||
|
s = recipe_json['servings'].split(' ')
|
||||||
|
recipe.servings = s[0]
|
||||||
|
recipe.servings_text = s[1]
|
||||||
|
|
||||||
|
if len(recipe_json['cook_time'].strip()) > 0:
|
||||||
|
recipe.waiting_time = re.findall(r'\d+', recipe_json['cook_time'])[0]
|
||||||
|
|
||||||
|
if len(recipe_json['prep_time'].strip()) > 0:
|
||||||
|
recipe.working_time = re.findall(r'\d+', recipe_json['prep_time'])[0]
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
recipe.save()
|
||||||
|
|
||||||
|
instructions = recipe_json['directions']
|
||||||
|
if len(recipe_json['notes'].strip()) > 0:
|
||||||
|
instructions += '\n\n### ' + _('Notes') + ' \n' + recipe_json['notes']
|
||||||
|
|
||||||
|
if len(recipe_json['nutritional_info'].strip()) > 0:
|
||||||
|
instructions += '\n\n### ' + _('Nutritional Information') + ' \n' + recipe_json['nutritional_info']
|
||||||
|
|
||||||
|
if len(recipe_json['source'].strip()) > 0 or len(recipe_json['source_url'].strip()) > 0:
|
||||||
|
instructions += '\n\n### ' + _('Source') + ' \n' + recipe_json['source'].strip() + ' \n' + recipe_json['source_url'].strip()
|
||||||
|
|
||||||
step = Step.objects.create(
|
step = Step.objects.create(
|
||||||
instruction=recipe_json['directions'] + '\n\n' + recipe_json['nutritional_info']
|
instruction=instructions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if 'categories' in recipe_json:
|
||||||
|
for c in recipe_json['categories']:
|
||||||
|
keyword, created = Keyword.objects.get_or_create(name=c.strip(), space=self.request.space)
|
||||||
|
recipe.keywords.add(keyword)
|
||||||
|
|
||||||
for ingredient in recipe_json['ingredients'].split('\n'):
|
for ingredient in recipe_json['ingredients'].split('\n'):
|
||||||
amount, unit, ingredient, note = parse(ingredient)
|
if len(ingredient.strip()) > 0:
|
||||||
f = get_food(ingredient, self.request.space)
|
amount, unit, ingredient, note = parse(ingredient)
|
||||||
u = get_unit(unit, self.request.space)
|
f = get_food(ingredient, self.request.space)
|
||||||
step.ingredients.add(Ingredient.objects.create(
|
u = get_unit(unit, self.request.space)
|
||||||
food=f, unit=u, amount=amount, note=note
|
step.ingredients.add(Ingredient.objects.create(
|
||||||
))
|
food=f, unit=u, amount=amount, note=note
|
||||||
|
))
|
||||||
|
|
||||||
recipe.steps.add(step)
|
recipe.steps.add(step)
|
||||||
|
|
||||||
|
@ -47,12 +47,13 @@ class RezKonv(Integration):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for ingredient in ingredients:
|
for ingredient in ingredients:
|
||||||
amount, unit, ingredient, note = parse(ingredient)
|
if len(ingredient.strip()) > 0:
|
||||||
f = get_food(ingredient, self.request.space)
|
amount, unit, ingredient, note = parse(ingredient)
|
||||||
u = get_unit(unit, self.request.space)
|
f = get_food(ingredient, self.request.space)
|
||||||
step.ingredients.add(Ingredient.objects.create(
|
u = get_unit(unit, self.request.space)
|
||||||
food=f, unit=u, amount=amount, note=note
|
step.ingredients.add(Ingredient.objects.create(
|
||||||
))
|
food=f, unit=u, amount=amount, note=note
|
||||||
|
))
|
||||||
recipe.steps.add(step)
|
recipe.steps.add(step)
|
||||||
|
|
||||||
return recipe
|
return recipe
|
||||||
|
@ -64,7 +64,7 @@ def import_recipe(request):
|
|||||||
files = []
|
files = []
|
||||||
for f in request.FILES.getlist('files'):
|
for f in request.FILES.getlist('files'):
|
||||||
files.append({'file': BytesIO(f.read()), 'name': f.name})
|
files.append({'file': BytesIO(f.read()), 'name': f.name})
|
||||||
t = threading.Thread(target=integration.do_import, args=[files, il, form['duplicates']])
|
t = threading.Thread(target=integration.do_import, args=[files, il, form.cleaned_data['duplicates']])
|
||||||
t.setDaemon(True)
|
t.setDaemon(True)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user