fixed paprika importer
This commit is contained in:
@ -20,8 +20,10 @@ class Paprika(Integration):
|
|||||||
recipe_json = json.loads(recipe_zip.read().decode("utf-8"))
|
recipe_json = json.loads(recipe_zip.read().decode("utf-8"))
|
||||||
|
|
||||||
recipe = Recipe.objects.create(
|
recipe = Recipe.objects.create(
|
||||||
name=recipe_json['name'].strip(), description=recipe_json['description'].strip(),
|
name=recipe_json['name'].strip(), created_by=self.request.user, internal=True, space=self.request.space)
|
||||||
created_by=self.request.user, internal=True, space=self.request.space)
|
|
||||||
|
if 'description' in recipe_json:
|
||||||
|
recipe.description = recipe_json['description'].strip()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if re.match(r'([0-9])+\s(.)*', recipe_json['servings'] ):
|
if re.match(r'([0-9])+\s(.)*', recipe_json['servings'] ):
|
||||||
@ -40,14 +42,17 @@ class Paprika(Integration):
|
|||||||
recipe.save()
|
recipe.save()
|
||||||
|
|
||||||
instructions = recipe_json['directions']
|
instructions = recipe_json['directions']
|
||||||
if len(recipe_json['notes'].strip()) > 0:
|
if recipe_json['notes'] and len(recipe_json['notes'].strip()) > 0:
|
||||||
instructions += '\n\n### ' + _('Notes') + ' \n' + recipe_json['notes']
|
instructions += '\n\n### ' + _('Notes') + ' \n' + recipe_json['notes']
|
||||||
|
|
||||||
if len(recipe_json['nutritional_info'].strip()) > 0:
|
if recipe_json['nutritional_info'] and len(recipe_json['nutritional_info'].strip()) > 0:
|
||||||
instructions += '\n\n### ' + _('Nutritional Information') + ' \n' + recipe_json['nutritional_info']
|
instructions += '\n\n### ' + _('Nutritional Information') + ' \n' + recipe_json['nutritional_info']
|
||||||
|
|
||||||
|
try:
|
||||||
if len(recipe_json['source'].strip()) > 0 or len(recipe_json['source_url'].strip()) > 0:
|
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()
|
instructions += '\n\n### ' + _('Source') + ' \n' + recipe_json['source'].strip() + ' \n' + recipe_json['source_url'].strip()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
step = Step.objects.create(
|
step = Step.objects.create(
|
||||||
instruction=instructions
|
instruction=instructions
|
||||||
@ -58,6 +63,7 @@ class Paprika(Integration):
|
|||||||
keyword, created = Keyword.objects.get_or_create(name=c.strip(), space=self.request.space)
|
keyword, created = Keyword.objects.get_or_create(name=c.strip(), space=self.request.space)
|
||||||
recipe.keywords.add(keyword)
|
recipe.keywords.add(keyword)
|
||||||
|
|
||||||
|
try:
|
||||||
for ingredient in recipe_json['ingredients'].split('\n'):
|
for ingredient in recipe_json['ingredients'].split('\n'):
|
||||||
if len(ingredient.strip()) > 0:
|
if len(ingredient.strip()) > 0:
|
||||||
amount, unit, ingredient, note = parse(ingredient)
|
amount, unit, ingredient, note = parse(ingredient)
|
||||||
@ -66,6 +72,8 @@ class Paprika(Integration):
|
|||||||
step.ingredients.add(Ingredient.objects.create(
|
step.ingredients.add(Ingredient.objects.create(
|
||||||
food=f, unit=u, amount=amount, note=note
|
food=f, unit=u, amount=amount, note=note
|
||||||
))
|
))
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
recipe.steps.add(step)
|
recipe.steps.add(step)
|
||||||
|
|
||||||
|
@ -421,6 +421,9 @@ class Comment(models.Model, PermissionModelMixin):
|
|||||||
def get_space_key():
|
def get_space_key():
|
||||||
return 'recipe', 'space'
|
return 'recipe', 'space'
|
||||||
|
|
||||||
|
def get_space(self):
|
||||||
|
return self.recipe.space
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.text
|
return self.text
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user