more cleanup from ugly merge
This commit is contained in:
@ -95,7 +95,7 @@ def find_recipe_json(ld_json, url, space):
|
||||
if 'recipeCuisine' in ld_json:
|
||||
keywords += listify_keywords(ld_json['recipeCuisine'])
|
||||
try:
|
||||
ld_json['keywords'] = parse_keywords(list(set(map(str.casefold, keywords))))
|
||||
ld_json['keywords'] = parse_keywords(list(set(map(str.casefold, keywords))), space)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
@ -197,7 +197,7 @@ def get_from_scraper(scrape, space):
|
||||
ingredients = []
|
||||
for x in scrape.ingredients():
|
||||
try:
|
||||
amount, unit, ingredient, note = parse_ingredient(x)
|
||||
amount, unit, ingredient, note = parse_single_ingredient(x)
|
||||
if ingredient:
|
||||
ingredients.append(
|
||||
{
|
||||
|
@ -137,7 +137,7 @@
|
||||
this.error = undefined
|
||||
this.parsed = true
|
||||
this.loading = true
|
||||
this.$http.post("{% url 'api_recipe_from_html' %}", {'html_text': this.html_recipe}, {emulateJSON: true}).then((response) => {
|
||||
this.$http.post("{% url 'api_manual_recipe_from_json' %}", {'html_text': this.html_recipe}, {emulateJSON: true}).then((response) => {
|
||||
console.log(response.data)
|
||||
this.recipe_data = response.data['recipe_data'];
|
||||
this.recipe_tree = response.data['recipe_tree'];
|
||||
|
@ -152,7 +152,7 @@
|
||||
this.error = undefined
|
||||
this.parsed = true
|
||||
this.loading = true
|
||||
this.$http.post("{% url 'api_recipe_from_html' %}", {'html_text': this.html_recipe}, {emulateJSON: true}).then((response) => {
|
||||
this.$http.post("{% url 'api_manual_recipe_from_json' %}", {'html_text': this.html_recipe}, {emulateJSON: true}).then((response) => {
|
||||
console.log(response.data)
|
||||
this.recipe_data = response.data['recipe_data'];
|
||||
this.recipe_tree = response.data['recipe_tree'];
|
||||
|
@ -52,7 +52,7 @@
|
||||
<div class="row tab-pane fade show" id="nav-ldjson" role="tabpanel">
|
||||
<div class="col-md-12">
|
||||
<div class="input-group input-group-lg">
|
||||
<textarea class="form-control input-group-append" v-model="json_data" rows=10 placeholder="{% trans 'Paste ld+json here to parse recipe automatically.' %}" style="font-size: 12px">
|
||||
<textarea class="form-control input-group-append" v-model="raw_data" rows=10 placeholder="{% trans 'Paste ld+json here to parse recipe automatically.' %}" style="font-size: 12px">
|
||||
</textarea>
|
||||
</div>
|
||||
<br>
|
||||
@ -66,7 +66,7 @@
|
||||
<div class="row tab-pane fade show" id="nav-json" role="tabpanel">
|
||||
<div class="col-md-12">
|
||||
<div class="input-group input-group-lg">
|
||||
<textarea class="form-control input-group-append" v-model="html_data" rows=10
|
||||
<textarea class="form-control input-group-append" v-model="raw_data" rows=10
|
||||
placeholder="{% trans 'To parse recipe manually: Paste JSON document here or a web page source that contains one or more JSON elements here.' %}" style="font-size: 12px">
|
||||
</textarea>
|
||||
</div>
|
||||
@ -81,7 +81,7 @@
|
||||
<div class="row tab-pane fade show" id="nav-html" role="tabpanel">
|
||||
<div class="col-md-12">
|
||||
<div class="input-group input-group-lg">
|
||||
<textarea class="form-control input-group-append" v-model="html_data" rows=10 placeholder="{% trans 'Paste html source here to parse recipe manually.' %}" style="font-size: 12px">
|
||||
<textarea class="form-control input-group-append" v-model="raw_data" rows=10 placeholder="{% trans 'Paste html source here to parse recipe manually.' %}" style="font-size: 12px">
|
||||
</textarea>
|
||||
</div>
|
||||
<br>
|
||||
@ -100,7 +100,7 @@
|
||||
<i class="fas fa-spinner fa-spin fa-8x"></i>
|
||||
</div>
|
||||
|
||||
<!-- recipe preview on HTML Import -->
|
||||
<!-- recipe preview before Import -->
|
||||
<div class="container-fluid" v-if="parsed" id="manage_tree">
|
||||
|
||||
<h2></h2>
|
||||
@ -274,7 +274,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- end of recipe preview on HTML Import -->
|
||||
<!-- end of recipe preview before Import -->
|
||||
|
||||
<template v-if="recipe_data !== undefined">
|
||||
|
||||
@ -515,7 +515,7 @@
|
||||
el: '#app',
|
||||
data: {
|
||||
remote_url: '',
|
||||
json_data: undefined,
|
||||
raw_data: undefined,
|
||||
keywords: [],
|
||||
keywords_loading: false,
|
||||
units: [],
|
||||
@ -530,8 +530,6 @@
|
||||
importing_recipe: false,
|
||||
recipe_json: undefined,
|
||||
recipe_tree: undefined,
|
||||
recipe_tree1: undefined,
|
||||
html_data: undefined,
|
||||
},
|
||||
directives: {
|
||||
tabindex: {
|
||||
@ -598,7 +596,7 @@
|
||||
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) => {
|
||||
this.$http.post("{% url 'api_recipe_from_json' %}", {'json': this.raw_data}, {emulateJSON: true}).then((response) => {
|
||||
console.log(response.data)
|
||||
this.recipe_data = response.data;
|
||||
this.loading = false
|
||||
@ -609,11 +607,13 @@
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
loadRecipeJson: function () {
|
||||
this.recipe_data = undefined
|
||||
loadRecipeHTML: function () {
|
||||
// TODO this needs refactored to get HTML elements
|
||||
this.error = undefined
|
||||
this.loading = true
|
||||
this.$http.post("{% url 'api_recipe_from_json' %}", {'json': this.json_data}, {emulateJSON: true}).then((response) => {
|
||||
this.parsed = false
|
||||
this.recipe_json['@type'] = "Recipe"
|
||||
this.$http.post("{% url 'api_recipe_from_json' %}", {'html': JSON.stringify(this.raw_data)}, {emulateJSON: true}).then((response) => {
|
||||
console.log(response.data)
|
||||
this.recipe_data = response.data;
|
||||
this.loading = false
|
||||
@ -630,10 +630,9 @@
|
||||
this.error = undefined
|
||||
|
||||
this.loading = true
|
||||
this.$http.post("{% url 'api_recipe_from_html' %}", {'html_data': this.html_data}, {emulateJSON: true}).then((response) => {
|
||||
this.$http.post("{% url 'api_manual_recipe_from_json' %}", {'data': this.raw_data}, {emulateJSON: true}).then((response) => {
|
||||
console.log(response.data)
|
||||
this.recipe_json = response.data['recipe_json'];
|
||||
this.recipe_tree1 = JSON.stringify(response.data['recipe_tree'], null, 2);
|
||||
this.recipe_tree = response.data['recipe_tree'];
|
||||
this.loading = false
|
||||
this.parsed = true
|
||||
@ -645,23 +644,6 @@
|
||||
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
|
||||
})
|
||||
},
|
||||
loadRecipeHTML: function () {
|
||||
// TODO this needs refactored to get HTML elements
|
||||
this.error = undefined
|
||||
this.loading = true
|
||||
this.parsed = false
|
||||
this.recipe_json['@type'] = "Recipe"
|
||||
this.$http.post("{% url 'api_recipe_from_json' %}", {'json': JSON.stringify(this.recipe_json)}, {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.recipe_data.name.length > 128) {
|
||||
this.makeToast(gettext('Error'), gettext('Recipe name is longer than 128 characters'), 'danger')
|
||||
|
@ -93,7 +93,7 @@ urlpatterns = [
|
||||
path('api/log_cooking/<int:recipe_id>/', api.log_cooking, name='api_log_cooking'),
|
||||
path('api/plan-ical/<slug:from_date>/<slug:to_date>/', 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-html/', api.recipe_from_html, name='api_recipe_from_html'),
|
||||
path('api/recipe-from-html/', api.manual_recipe_from_json, name='api_manual_recipe_from_json'),
|
||||
path('api/recipe-from-json/', api.recipe_from_json, name='api_recipe_from_json'),
|
||||
path('api/backup/', api.get_backup, name='api_backup'),
|
||||
path('api/ingredient-from-string/', api.ingredient_from_string, name='api_ingredient_from_string'),
|
||||
|
@ -607,9 +607,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, ''))
|
||||
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,
|
||||
@ -698,14 +706,14 @@ def recipe_from_url(request):
|
||||
|
||||
|
||||
@group_required('user')
|
||||
def recipe_from_html(request):
|
||||
html_data = request.POST['html_data']
|
||||
recipe_json, recipe_tree = get_from_raw(html_data)
|
||||
def manual_recipe_from_json(request):
|
||||
json_data = request.POST['data']
|
||||
recipe_json, recipe_tree = get_from_raw(json_data)
|
||||
if len(recipe_tree) == 0 and len(recipe_json) == 0:
|
||||
return JsonResponse(
|
||||
{
|
||||
'error': True,
|
||||
'msg': _('The requested page refused to provide any information (Status Code 403).') # noqa: E501
|
||||
'msg': _('No useable data could be found.') # noqa: E501
|
||||
},
|
||||
status=400
|
||||
)
|
||||
|
@ -132,13 +132,11 @@ def import_url(request):
|
||||
recipe.steps.add(step)
|
||||
|
||||
for kw in data['keywords']:
|
||||
# if k := Keyword.objects.filter(name=kw['text'], space=request.space).first():
|
||||
# recipe.keywords.add(k)
|
||||
# elif data['all_keywords']:
|
||||
# k = Keyword.objects.create(name=kw['text'], space=request.space)
|
||||
# recipe.keywords.add(k)
|
||||
k, created = Keyword.objects.get_or_create(name=kw['text'].strip(), space=request.space)
|
||||
recipe.keywords.add(k)
|
||||
if k := Keyword.objects.filter(name=kw['text'], space=request.space).first():
|
||||
recipe.keywords.add(k)
|
||||
elif data['all_keywords']:
|
||||
k = Keyword.objects.create(name=kw['text'])
|
||||
recipe.keywords.add(k)
|
||||
|
||||
for ing in data['recipeIngredient']:
|
||||
ingredient = Ingredient()
|
||||
|
Reference in New Issue
Block a user