combined json import and source import

This commit is contained in:
smilerz
2021-03-21 13:13:56 -05:00
parent 4015517c0a
commit 40a2f7ff90
5 changed files with 98 additions and 137 deletions

View File

@@ -28,8 +28,8 @@ from cookbook.helper.permission_helper import (CustomIsAdmin, CustomIsGuest,
CustomIsOwner, CustomIsShare,
CustomIsShared, CustomIsUser,
group_required)
from cookbook.helper.recipe_url_import import get_from_html, find_recipe_json
from cookbook.helper.recipe_html_import import get_from_raw
from cookbook.helper.recipe_html_import import get_recipe_from_source
from cookbook.helper.recipe_url_import import get_from_scraper, find_recipe_json
from cookbook.models import (CookLog, Food, Ingredient, Keyword, MealPlan,
MealType, Recipe, RecipeBook, ShoppingList,
ShoppingListEntry, ShoppingListRecipe, Step,
@@ -616,9 +616,11 @@ def recipe_from_url_old(request):
@group_required('user')
def manual_recipe_from_json(request):
def recipe_from_source(request):
json_data = request.POST['data']
recipe_json, recipe_tree = get_from_raw(json_data, request.space)
auto = request.POST['auto']
recipe_json, recipe_tree = get_recipe_from_source(json_data, request.space)
if len(recipe_tree) == 0 and len(recipe_json) == 0:
return JsonResponse(
{
@@ -628,10 +630,18 @@ def manual_recipe_from_json(request):
status=400
)
else:
return JsonResponse({
'recipe_tree': recipe_tree,
'recipe_json': recipe_json
})
if auto == "true":
return JsonResponse({'recipe_json': recipe_json})
else:
# overide keyword structure from dict to list
kws = []
for kw in recipe_json['keywords']:
kws.append(kw['text'])
recipe_json['keywords'] = kws
return JsonResponse({
'recipe_tree': recipe_tree,
'recipe_json': recipe_json
})
@group_required('admin')