diff --git a/cookbook/helper/recipe_html_import.py b/cookbook/helper/recipe_html_import.py index 6df0ce1a7..3bcc51587 100644 --- a/cookbook/helper/recipe_html_import.py +++ b/cookbook/helper/recipe_html_import.py @@ -58,6 +58,7 @@ def get_recipe_from_source(text, url, space): recipe_json = { 'name': '', + 'url': '', 'description': '', 'image': '', 'keywords': [], diff --git a/cookbook/helper/recipe_url_import.py b/cookbook/helper/recipe_url_import.py index 49fb7305d..6c0665f69 100644 --- a/cookbook/helper/recipe_url_import.py +++ b/cookbook/helper/recipe_url_import.py @@ -102,6 +102,7 @@ def get_from_scraper(scrape, space): recipe_json['recipeInstructions'] = "" if scrape.url: + recipe_json['url'] = scrape.url recipe_json['recipeInstructions'] += "\n\nImported from " + scrape.url return recipe_json diff --git a/cookbook/templates/url_import.html b/cookbook/templates/url_import.html index 066d85035..4f48c7234 100644 --- a/cookbook/templates/url_import.html +++ b/cookbook/templates/url_import.html @@ -22,20 +22,13 @@ {% block content %}
-
-

{% trans 'Import' %}

- - {% trans 'Bookmark Me!' %} -
-
- @@ -177,7 +170,7 @@
-
[[kw]]
+
[[kw.text]]
@@ -273,7 +266,7 @@
- @@ -638,6 +631,7 @@ recipe_app: 'DEFAULT', recipe_files: [], images: [], + mode: 'url' }, directives: { tabindex: { @@ -675,51 +669,20 @@ this.error = undefined this.loading = true this.preview = false - if (this.automatic) { - console.log('true') - } - this.$http.post("{% url 'api_recipe_from_url' %}", {'url': this.remote_url, 'auto':this.automatic}, {emulateJSON: true}).then((response) => { + this.$http.post("{% url 'api_recipe_from_source' %}", { + 'url': this.remote_url, + 'data': this.source_data, + 'auto':this.automatic, + 'mode':this.mode}, {emulateJSON: true}).then((response) => { console.log(response.data) + this.recipe_json = response.data['recipe_json']; + this.recipe_tree = response.data['recipe_tree']; + this.recipe_html = response.data['recipe_html']; + this.images = response.data['images']; if (this.automatic) { - this.recipe_data = response.data; - } else { - this.recipe_json = response.data['recipe_json']; - this.recipe_tree = response.data['recipe_tree']; - this.recipe_html = response.data['recipe_html']; - this.images = response.data['images']; - this.preview = true - } - this.loading = false - }).catch((err) => { - this.error = err.data - this.loading = false - console.log(err) - let msg = gettext('There was an error loading a resource!') - if (err.bodyText.length < 300) { - msg += err.bodyText - } else { - msg += ' ' + err.status + ' ' + err.statusText - } - this.makeToast(gettext('Error'), msg, 'danger') - }) - }, - loadSource: function() { - this.recipe_data = undefined - this.recipe_json = undefined - this.recipe_tree = undefined - this.images = [] - this.error = undefined - this.loading = true - this.preview = false - this.$http.post("{% url 'api_recipe_from_source' %}", {'data': this.source_data, 'url': this.remote_url, 'auto':this.automatic}, {emulateJSON: true}).then((response) => { - console.log(response.data) - if (this.automatic) { - this.recipe_data = response.data['recipe_json']; + this.recipe_data = this.recipe_json; this.preview = false } else { - this.recipe_json = response.data['recipe_json']; - this.recipe_tree = response.data['recipe_tree']; - this.recipe_html = response.data['recipe_html']; this.preview = true } this.loading = false @@ -759,22 +722,9 @@ this.makeToast(gettext('Error'), gettext('There was an error deleting bookmarklet!') + err.bodyText, 'danger') }) }, - loadRecipeManual: function () { - this.error = undefined + showRecipe: function() { this.preview = false - this.loading = true - this.recipe_json['@type'] = "Recipe" - this.$http.post("{% url 'api_recipe_from_source' %}", {'data': JSON.stringify(this.recipe_json), 'auto':'true'}, {emulateJSON: true}).then((response) => { - console.log(response.data) - this.recipe_data = response.data['recipe_json']; - this.loading = false - this.preview = 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') - }) + this.recipe_data = this.recipe_json }, importRecipe: function () { if (this.recipe_data.name.length > 128) { @@ -950,7 +900,8 @@ this.recipe_json.image=v break; case 'keywords': - this.recipe_json.keywords.push(v) + let new_keyword = {'text': v, 'id': null} + this.recipe_json.keywords.push(new_keyword) break; case 'servings': this.recipe_json.servings=v diff --git a/cookbook/urls.py b/cookbook/urls.py index f9810aa06..f26ce8b4a 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -93,7 +93,6 @@ urlpatterns = [ path('api/sync_all/', api.sync_all, name='api_sync'), 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-source/', api.recipe_from_source, name='api_recipe_from_source'), path('api/backup/', api.get_backup, name='api_backup'), path('api/ingredient-from-string/', api.ingredient_from_string, name='api_ingredient_from_string'),