redirect to import url for processing
This commit is contained in:
parent
5e27cd606e
commit
c8a4861df8
@ -118,7 +118,7 @@ def get_recipe_from_source(text, url, space):
|
|||||||
temp_tree.append(node)
|
temp_tree.append(node)
|
||||||
|
|
||||||
if '@type' in el and el['@type'] == 'Recipe':
|
if '@type' in el and el['@type'] == 'Recipe':
|
||||||
recipe_json = helper.find_recipe_json(el, None, space)
|
recipe_json = helper.find_recipe_json(el, url, space)
|
||||||
recipe_tree += [{'name': 'ld+json', 'children': temp_tree}]
|
recipe_tree += [{'name': 'ld+json', 'children': temp_tree}]
|
||||||
else:
|
else:
|
||||||
recipe_tree += [{'name': 'json', 'children': temp_tree}]
|
recipe_tree += [{'name': 'json', 'children': temp_tree}]
|
||||||
|
@ -86,6 +86,9 @@ def find_recipe_json(ld_json, url, space):
|
|||||||
else:
|
else:
|
||||||
ld_json['recipeInstructions'] = ""
|
ld_json['recipeInstructions'] = ""
|
||||||
|
|
||||||
|
if url:
|
||||||
|
ld_json['recipeInstructions'] += "\nImported from " + url
|
||||||
|
|
||||||
if 'image' in ld_json:
|
if 'image' in ld_json:
|
||||||
ld_json['image'] = parse_image(ld_json['image'])
|
ld_json['image'] = parse_image(ld_json['image'])
|
||||||
else:
|
else:
|
||||||
|
@ -30,18 +30,18 @@
|
|||||||
title="{% trans 'Drag me to your bookmarks to import recipes from anywhere' %}">
|
title="{% trans 'Drag me to your bookmarks to import recipes from anywhere' %}">
|
||||||
<img src="{% static 'assets/favicon-16x16.png' %}">{% trans 'Bookmark Me!' %} </a>
|
<img src="{% static 'assets/favicon-16x16.png' %}">{% trans 'Bookmark Me!' %} </a>
|
||||||
</div>
|
</div>
|
||||||
<nav class="nav nav-pills flex-sm-row" style="margin-bottom:10px">
|
<nav class="nav nav-pills flex-sm-row" id="nav-tabs" style="margin-bottom:10px">
|
||||||
<a class="nav-link active" href="#nav-url" data-toggle="tab" role="tab" aria-controls="nav-url" aria-selected="true">URL</a>
|
<a class="nav-link active" href="#nav-url" data-toggle="tab" role="tab" >URL</a>
|
||||||
<a class="nav-link" href="#nav-app" data-toggle="tab" role="tab" aria-controls="nav-app">App</a>
|
<a class="nav-link" href="#nav-app" data-toggle="tab" role="tab" >App</a>
|
||||||
<a class="nav-link" href="#nav-source" data-toggle="tab" role="tab" aria-controls="nav-source">Source</a>
|
<a class="nav-link" href="#nav-source" data-toggle="tab" role="tab" >Source</a>
|
||||||
<a class="nav-link disabled" href="#nav-text" data-toggle="tab" role="tab" aria-controls="nav-text">Text</a>
|
<a class="nav-link disabled" href="#nav-text" data-toggle="tab" role="tab" >Text</a>
|
||||||
<a class="nav-link disabled" href="#nav-file" data-toggle="tab" role="tab" aria-controls="nav-file">File</a>
|
<a class="nav-link disabled" href="#nav-file" data-toggle="tab" role="tab" >File</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|
||||||
<div class="tab-content" id="nav-tabContent">
|
<div class="tab-content" id="nav-tabContent">
|
||||||
<!-- Import URL -->
|
<!-- Import URL -->
|
||||||
<div class="tab-pane fade show active" id="nav-url" role="tabpanel">
|
<div class="tab-pane fade show active" role="tabpanel">
|
||||||
<div class="btn-group btn-group-toggle" data-toggle="buttons">
|
<div class="btn-group btn-group-toggle" data-toggle="buttons">
|
||||||
<label class="btn btn-outline-info btn-sm active" @click="automatic=true">
|
<label class="btn btn-outline-info btn-sm active" @click="automatic=true">
|
||||||
<input type="radio" autocomplete="off" checked> Automatic
|
<input type="radio" autocomplete="off" checked> Automatic
|
||||||
@ -625,13 +625,13 @@
|
|||||||
recipe_data: undefined,
|
recipe_data: undefined,
|
||||||
error: undefined,
|
error: undefined,
|
||||||
loading: false,
|
loading: false,
|
||||||
preview: {{preview}},
|
preview: undefined,
|
||||||
preview_type: 'json',
|
preview_type: 'json',
|
||||||
all_keywords: false,
|
all_keywords: false,
|
||||||
importing_recipe: false,
|
importing_recipe: false,
|
||||||
recipe_json: {{recipe_json|safe}},
|
recipe_json: undefined,
|
||||||
recipe_tree: {{recipe_tree|safe}},
|
recipe_tree: undefined,
|
||||||
recipe_html: {{recipe_html|safe}},
|
recipe_html: undefined,
|
||||||
automatic: true,
|
automatic: true,
|
||||||
show_blank: false,
|
show_blank: false,
|
||||||
blank_field: '',
|
blank_field: '',
|
||||||
@ -650,7 +650,12 @@
|
|||||||
this.searchKeywords('')
|
this.searchKeywords('')
|
||||||
this.searchUnits('')
|
this.searchUnits('')
|
||||||
this.searchIngredients('')
|
this.searchIngredients('')
|
||||||
|
let uri = window.location.search.substring(1);
|
||||||
|
let params = new URLSearchParams(uri);
|
||||||
|
q = params.get("id")
|
||||||
|
if (q) {
|
||||||
|
this.loadBookmarklet(q)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
makeToast: function (title, message, variant = null) {
|
makeToast: function (title, message, variant = null) {
|
||||||
@ -706,7 +711,7 @@
|
|||||||
this.error = undefined
|
this.error = undefined
|
||||||
this.loading = true
|
this.loading = true
|
||||||
this.preview = false
|
this.preview = false
|
||||||
this.$http.post("{% url 'api_recipe_from_source' %}", {'data': this.source_data, 'auto':this.automatic}, {emulateJSON: true}).then((response) => {
|
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)
|
console.log(response.data)
|
||||||
if (this.automatic) {
|
if (this.automatic) {
|
||||||
this.recipe_data = response.data['recipe_json'];
|
this.recipe_data = response.data['recipe_json'];
|
||||||
@ -731,6 +736,26 @@
|
|||||||
this.makeToast(gettext('Error'), msg, 'danger')
|
this.makeToast(gettext('Error'), msg, 'danger')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
loadBookmarklet: function(id_bkmk) {
|
||||||
|
let uri = window.location.search.substring(1);
|
||||||
|
let params = new URLSearchParams(uri);
|
||||||
|
q = params.get("id")
|
||||||
|
console.log(q)
|
||||||
|
this.error = undefined
|
||||||
|
this.loading = true
|
||||||
|
this.$http.get("{% url 'api:bookmarkletimport-list' %}?id=" + id_bkmk ).then((response) => {
|
||||||
|
console.log(response.data)
|
||||||
|
this.automatic = false
|
||||||
|
this.source_data = response.data[0]['html']
|
||||||
|
this.remote_url = response.data[0]['url']
|
||||||
|
this.loadSource()
|
||||||
|
}).catch((err) => {
|
||||||
|
this.error = err.data
|
||||||
|
this.loading = false
|
||||||
|
console.log(err)
|
||||||
|
this.makeToast(gettext('Error'), gettext('There was an error loading bookmarklet!') + err.bodyText, 'danger')
|
||||||
|
})
|
||||||
|
},
|
||||||
loadRecipeManual: function () {
|
loadRecipeManual: function () {
|
||||||
this.error = undefined
|
this.error = undefined
|
||||||
this.preview = false
|
this.preview = false
|
||||||
@ -931,7 +956,7 @@
|
|||||||
console.log(response)
|
console.log(response)
|
||||||
let new_ingredient={
|
let new_ingredient={
|
||||||
unit: {id: Math.random() * 1000, text: response.body.unit},
|
unit: {id: Math.random() * 1000, text: response.body.unit},
|
||||||
amount: response.body.amount,
|
amount: String(response.body.amount),
|
||||||
ingredient: {id: Math.random() * 1000, text: response.body.food},
|
ingredient: {id: Math.random() * 1000, text: response.body.food},
|
||||||
note: response.body.note
|
note: response.body.note
|
||||||
}
|
}
|
||||||
|
@ -621,6 +621,8 @@ def recipe_from_source(request, url=None, url_text=None):
|
|||||||
auto = request.POST['auto']
|
auto = request.POST['auto']
|
||||||
else:
|
else:
|
||||||
auto = 'true'
|
auto = 'true'
|
||||||
|
if 'url' in request.POST:
|
||||||
|
url = request.POST['url']
|
||||||
|
|
||||||
recipe_json, recipe_tree, recipe_html, images = get_recipe_from_source(json_data, url, request.space)
|
recipe_json, recipe_tree, recipe_html, images = get_recipe_from_source(json_data, url, request.space)
|
||||||
if len(recipe_tree) == 0 and len(recipe_json) == 0:
|
if len(recipe_tree) == 0 and len(recipe_json) == 0:
|
||||||
|
@ -184,7 +184,12 @@ def import_url(request):
|
|||||||
|
|
||||||
return HttpResponse(reverse('view_recipe', args=[recipe.pk]))
|
return HttpResponse(reverse('view_recipe', args=[recipe.pk]))
|
||||||
|
|
||||||
return render(request, 'url_import.html', {})
|
if 'id' in request.GET:
|
||||||
|
context = {'bookmarklet': 25}
|
||||||
|
else:
|
||||||
|
context = {}
|
||||||
|
|
||||||
|
return render(request, 'url_import.html', context)
|
||||||
|
|
||||||
|
|
||||||
class Object(object):
|
class Object(object):
|
||||||
|
Loading…
Reference in New Issue
Block a user