diff --git a/cookbook/helper/recipe_url_import.py b/cookbook/helper/recipe_url_import.py
index b2bb5338a..959545c2b 100644
--- a/cookbook/helper/recipe_url_import.py
+++ b/cookbook/helper/recipe_url_import.py
@@ -84,6 +84,7 @@ def find_recipe_json(ld_json, url, space):
for x in ld_json['recipeIngredient']:
if x.replace(' ', '') != '':
+ x = x.replace('½', "0.5").replace('¼', "0.25").replace('¾', "0.75")
try:
amount, unit, ingredient, note = parse_ingredient(x)
if ingredient:
diff --git a/cookbook/templates/url_import.html b/cookbook/templates/url_import.html
index 0fdc81141..0481e7d1a 100644
--- a/cookbook/templates/url_import.html
+++ b/cookbook/templates/url_import.html
@@ -30,6 +30,19 @@
+
+
@@ -322,6 +335,21 @@
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
})
},
+ loadRecipeJson: function () {
+ this.recipe_data = undefined
+ this.error = undefined
+ this.loading = true
+ this.$http.post("{% url 'api_recipe_from_json' %}", {'json': this.json_data}, {emulateJSON: true}).then((response) => {
+ console.log(response.data)
+ this.recipe_data = response.data;
+ this.loading = false
+ }).catch((err) => {
+ this.error = err.data
+ this.loading = false
+ console.log(err)
+ this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
+ })
+ },
importRecipe: function () {
if (this.importing_recipe) {
this.makeToast(gettext('Error'), gettext('Already importing the selected recipe, please wait!'), 'danger')
@@ -361,7 +389,7 @@
this.recipe_data.recipeIngredient[index] = new_unit
},
addKeyword: function (tag) {
- let new_keyword = {'text':tag,'id':null}
+ let new_keyword = {'text': tag, 'id': null}
this.recipe_data.keywords.push(new_keyword)
},
openUnitSelect: function (id) {
diff --git a/cookbook/urls.py b/cookbook/urls.py
index 4f0557033..cc5626533 100644
--- a/cookbook/urls.py
+++ b/cookbook/urls.py
@@ -91,6 +91,7 @@ urlpatterns = [
path('api/log_cooking//', api.log_cooking, name='api_log_cooking'),
path('api/plan-ical///', api.get_plan_ical, name='api_get_plan_ical'),
path('api/recipe-from-url/', api.recipe_from_url, name='api_recipe_from_url'),
+ path('api/recipe-from-json/', api.recipe_from_json, name='api_recipe_from_json'),
path('api/ingredient-from-string/', api.ingredient_from_string, name='api_ingredient_from_string'),
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'),
diff --git a/cookbook/views/api.py b/cookbook/views/api.py
index da307b8c6..3db330669 100644
--- a/cookbook/views/api.py
+++ b/cookbook/views/api.py
@@ -27,7 +27,7 @@ from cookbook.helper.permission_helper import (CustomIsAdmin, CustomIsGuest,
CustomIsOwner, CustomIsShare,
CustomIsShared, CustomIsUser,
group_required)
-from cookbook.helper.recipe_url_import import get_from_html
+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,
@@ -337,7 +337,7 @@ class RecipeViewSet(viewsets.ModelViewSet, StandardFilterMixin):
class ShoppingListRecipeViewSet(viewsets.ModelViewSet):
queryset = ShoppingListRecipe.objects
serializer_class = ShoppingListRecipeSerializer
- permission_classes = [CustomIsOwner| CustomIsShared ]
+ permission_classes = [CustomIsOwner | CustomIsShared]
def get_queryset(self):
return self.queryset.filter(Q(shoppinglist__created_by=self.request.user) | Q(shoppinglist__shared=self.request.user)).filter(shoppinglist__space=self.request.space).all()
@@ -546,6 +546,23 @@ def recipe_from_url(request):
return get_from_html(response.text, url, request.space)
+@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, '', request.space))
+ return JsonResponse(
+ {
+ 'error': True,
+ 'msg': _('Could not parse correctly...')
+ },
+ status=400
+ )
+
+
@group_required('user')
def ingredient_from_string(request):
text = request.POST['text']