Allow recipes to be imported from json directly

This commit is contained in:
Patrick Pirker
2021-03-03 21:37:39 +01:00
committed by smilerz
parent 17c5084bc0
commit 386834f409
3 changed files with 47 additions and 2 deletions

View File

@ -27,8 +27,8 @@ from cookbook.helper.ingredient_parser import parse
from cookbook.helper.permission_helper import (CustomIsAdmin, CustomIsGuest,
CustomIsOwner, CustomIsShare,
CustomIsShared, CustomIsUser,
group_required, share_link_valid)
from cookbook.helper.recipe_url_import import get_from_html, get_from_scraper, find_recipe_json
group_required)
from cookbook.helper.recipe_url_import import get_from_html, find_recipe_json
from cookbook.models import (CookLog, Food, Ingredient, Keyword, MealPlan,
MealType, Recipe, RecipeBook, ShoppingList,
ShoppingListEntry, ShoppingListRecipe, Step,
@ -533,6 +533,23 @@ def get_plan_ical(request, from_date, to_date):
return response
@group_required('user')
def recipe_from_json(request):
mjson = request.POST['json']
md_json = json.loads(mjson)
if ('@type' in md_json
and md_json['@type'] == 'Recipe'):
return JsonResponse(find_recipe_json(md_json, ''))
return JsonResponse(
{
'error': True,
'msg': _('Could not parse correctly...')
},
status=400
)
@group_required('user')
def recipe_from_url(request):
url = request.POST['url']