mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-08 23:58:15 -05:00
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']
|
||||||
|
|
||||||
if len(recipe_json['source'].strip()) > 0 or len(recipe_json['source_url'].strip()) > 0:
|
try:
|
||||||
instructions += '\n\n### ' + _('Source') + ' \n' + recipe_json['source'].strip() + ' \n' + recipe_json['source_url'].strip()
|
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()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
step = Step.objects.create(
|
step = Step.objects.create(
|
||||||
instruction=instructions
|
instruction=instructions
|
||||||
@@ -58,14 +63,17 @@ 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)
|
||||||
|
|
||||||
for ingredient in recipe_json['ingredients'].split('\n'):
|
try:
|
||||||
if len(ingredient.strip()) > 0:
|
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
|
||||||
|
))
|
||||||
|
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