Merge pull request #501 from smilerz/main_fork

fix json direct import when wrapped in @graph
This commit is contained in:
vabene1111 2021-03-20 22:26:06 +01:00 committed by GitHub
commit e15c92cda5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -214,7 +214,7 @@ def find_recipe_json(ld_json, url, space):
for key in list(ld_json):
if key not in [
'prepTime', 'cookTime', 'image', 'recipeInstructions',
'keywords', 'name', 'recipeIngredient', 'servings'
'keywords', 'name', 'recipeIngredient', 'servings', 'description'
]:
ld_json.pop(key, None)

View File

@ -589,9 +589,17 @@ 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, '', request.space))
for ld_json_item in md_json:
# recipes type might be wrapped in @graph type
if '@graph' in ld_json_item:
for x in md_json['@graph']:
if '@type' in x and x['@type'] == 'Recipe':
md_json = x
if ('@type' in md_json
and md_json['@type'] == 'Recipe'):
return JsonResponse(find_recipe_json(md_json, '', request.space))
return JsonResponse(
{
'error': True,