mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-08 23:58:15 -05:00
Merge branch 'develop' into bookmarklet
This commit is contained in:
@@ -2,6 +2,7 @@ import random
|
||||
import re
|
||||
from isodate import parse_duration as iso_parse_duration
|
||||
from isodate.isoerror import ISO8601Error
|
||||
from recipe_scrapers._exceptions import ElementNotFoundInHtml
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse as parse_single_ingredient
|
||||
from cookbook.models import Keyword
|
||||
@@ -17,12 +18,12 @@ def get_from_scraper(scrape, space):
|
||||
recipe_json = {}
|
||||
try:
|
||||
recipe_json['name'] = parse_name(scrape.title() or scrape.schema.data.get('name') or '')
|
||||
except (TypeError, AttributeError):
|
||||
except (TypeError, AttributeError,ElementNotFoundInHtml):
|
||||
recipe_json['name'] = ''
|
||||
|
||||
try:
|
||||
description = scrape.schema.data.get("description") or ''
|
||||
except AttributeError:
|
||||
except (AttributeError,ElementNotFoundInHtml):
|
||||
description = ''
|
||||
|
||||
recipe_json['description'] = parse_description(description)
|
||||
@@ -30,21 +31,27 @@ def get_from_scraper(scrape, space):
|
||||
try:
|
||||
servings = scrape.yields()
|
||||
servings = int(re.findall(r'\b\d+\b', servings)[0])
|
||||
except (AttributeError, ValueError, IndexError):
|
||||
except (AttributeError,ElementNotFoundInHtml, ValueError, IndexError):
|
||||
servings = 1
|
||||
recipe_json['servings'] = servings
|
||||
|
||||
recipe_json['prepTime'] = get_minutes(scrape.schema.data.get("prepTime")) or 0
|
||||
recipe_json['cookTime'] = get_minutes(scrape.schema.data.get("cookTime")) or 0
|
||||
try:
|
||||
recipe_json['prepTime'] = get_minutes(scrape.schema.data.get("prepTime")) or 0
|
||||
except (AttributeError, ElementNotFoundInHtml):
|
||||
recipe_json['prepTime'] = 0
|
||||
try:
|
||||
recipe_json['cookTime'] = get_minutes(scrape.schema.data.get("cookTime")) or 0
|
||||
except (AttributeError, ElementNotFoundInHtml):
|
||||
recipe_json['cookTime'] = 0
|
||||
if recipe_json['cookTime'] + recipe_json['prepTime'] == 0:
|
||||
try:
|
||||
recipe_json['prepTime'] = get_minutes(scrape.total_time()) or 0
|
||||
except AttributeError:
|
||||
except (AttributeError,ElementNotFoundInHtml):
|
||||
pass
|
||||
|
||||
try:
|
||||
recipe_json['image'] = parse_image(scrape.image()) or ''
|
||||
except (AttributeError, TypeError, SchemaOrgException):
|
||||
except (AttributeError,ElementNotFoundInHtml, TypeError, SchemaOrgException):
|
||||
recipe_json['image'] = ''
|
||||
|
||||
keywords = []
|
||||
@@ -56,7 +63,7 @@ def get_from_scraper(scrape, space):
|
||||
if scrape.schema.data.get('recipeCuisine'):
|
||||
keywords += listify_keywords(scrape.schema.data.get("recipeCuisine"))
|
||||
recipe_json['keywords'] = parse_keywords(list(set(map(str.casefold, keywords))), space)
|
||||
except AttributeError:
|
||||
except (AttributeError,ElementNotFoundInHtml):
|
||||
recipe_json['keywords'] = keywords
|
||||
|
||||
try:
|
||||
@@ -97,12 +104,12 @@ def get_from_scraper(scrape, space):
|
||||
}
|
||||
)
|
||||
recipe_json['recipeIngredient'] = ingredients
|
||||
except AttributeError:
|
||||
except (AttributeError,ElementNotFoundInHtml):
|
||||
recipe_json['recipeIngredient'] = ingredients
|
||||
|
||||
try:
|
||||
recipe_json['recipeInstructions'] = parse_instructions(scrape.instructions())
|
||||
except AttributeError:
|
||||
except (AttributeError,ElementNotFoundInHtml):
|
||||
recipe_json['recipeInstructions'] = ""
|
||||
|
||||
if scrape.url:
|
||||
|
||||
@@ -83,6 +83,25 @@
|
||||
<label class="btn btn-outline-info btn-sm" @click="recipe_app='SAFRON'">
|
||||
<input type="radio" autocomplete="off"> Safron
|
||||
</label>
|
||||
<label class="btn btn-outline-info btn-sm" @click="recipe_app='CHEFTAP'">
|
||||
<input type="radio" autocomplete="off"> Cheftap
|
||||
</label>
|
||||
<label class="btn btn-outline-info btn-sm" @click="recipe_app='PEPPERPLATE'">
|
||||
<input type="radio" autocomplete="off"> Pepperplate
|
||||
</label>
|
||||
<label class="btn btn-outline-info btn-sm" @click="recipe_app='RECIPESAGE'">
|
||||
<input type="radio" autocomplete="off"> Recipesage
|
||||
</label>
|
||||
<label class="btn btn-outline-info btn-sm" @click="recipe_app='DOMESTICA'">
|
||||
<input type="radio" autocomplete="off"> Domestica
|
||||
</label>
|
||||
<label class="btn btn-outline-info btn-sm" @click="recipe_app='MEALMASTER'">
|
||||
<input type="radio" autocomplete="off"> Mealmaster
|
||||
</label>
|
||||
<label class="btn btn-outline-info btn-sm" @click="recipe_app='REZKONV'">
|
||||
<input type="radio" autocomplete="off"> Rezkonv
|
||||
</label>
|
||||
|
||||
</div>
|
||||
<b-form-file
|
||||
class="my-2"
|
||||
@@ -113,7 +132,7 @@
|
||||
</textarea>
|
||||
</div>
|
||||
<button @click="loadRecipe()" class="btn btn-primary shadow-none" type="button"
|
||||
id="id_btn_app"><i class="fas fa-code"></i> {% trans 'Import' %}
|
||||
id="id_btn_app"><i class="fas fa-code"></i> {% trans 'Import' %}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -274,18 +293,18 @@
|
||||
</div>
|
||||
<br/>
|
||||
<!-- end of preview card -->
|
||||
<button @click="showRecipe()" class="btn btn-primary shadow-none" type="button"
|
||||
<button @click="showRecipe()" class="btn btn-primary shadow-none" type="button" style="margin-bottom: 2vh"
|
||||
id="id_btn_json"><i class="fas fa-code"></i> {% trans 'Import' %}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- start of source data -->
|
||||
<div class="col" style="max-width:50%">
|
||||
<div class="card card-border-primary">
|
||||
<div class="col" style="max-width:50%;">
|
||||
<div class="card card-border-primary sticky-top" style="z-index: 100;">
|
||||
<div class="card-header">
|
||||
<h3>{% trans 'Discovered Attributes' %}</h3>
|
||||
<div class='small text-muted'>
|
||||
{% trans 'Drag recipe attributes from below into the appropriate box on the left. Click any node to display its full properties.' %}
|
||||
{% trans 'Drag recipe attributes from below into the appropriate box on the left. Click any node to display its full properties.' %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group btn-group-toggle" data-toggle="buttons">
|
||||
@@ -299,8 +318,8 @@
|
||||
<input type="radio" autocomplete="off"> images
|
||||
</label>
|
||||
</div>
|
||||
<i :class="[show_blank ? 'fa-chevron-up' : 'fa-chevron-down', 'fas']"
|
||||
style="cursor:pointer;"
|
||||
<i :class="[show_blank ? 'fa-chevron-up' : 'fa-chevron-down', 'fas']"
|
||||
style="cursor:pointer;"
|
||||
@click="show_blank=!show_blank"
|
||||
title="{% trans 'Show Blank Field' %}"></i>
|
||||
<div class="card-body p-1">
|
||||
@@ -312,9 +331,9 @@
|
||||
</div>
|
||||
<div class="small text-muted">{% trans 'Items dragged to Blank Field will be appended.'%}</div>
|
||||
</div>
|
||||
<div class="card-body drop-zone"
|
||||
@drop="replacePreview('blank', $event)"
|
||||
@dragover.prevent
|
||||
<div class="card-body drop-zone"
|
||||
@drop="replacePreview('blank', $event)"
|
||||
@dragover.prevent
|
||||
@dragenter.prevent
|
||||
draggable
|
||||
@dragstart="htmlDragStart($event)">
|
||||
@@ -332,7 +351,7 @@
|
||||
<div class="col" @click.ctrl="customItemClickWithCtrl">
|
||||
<div class="row clearfix" style="width:100%" >
|
||||
<div class="col-es" style="align-right">
|
||||
<button style="border: 0px; background-color: transparent; cursor: pointer;"
|
||||
<button style="border: 0px; background-color: transparent; cursor: pointer;"
|
||||
@click="deleteNode(_.vm, _.model, $event)"><i class="fas fa-minus-square" style="color:red"></i></button>
|
||||
</div>
|
||||
<div class="col overflow-hidden">
|
||||
@@ -343,17 +362,17 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</template>
|
||||
</v-jstree>
|
||||
<!-- start of html data -->
|
||||
<div v-if="preview_type=='html'">
|
||||
<ul class="list-group list-group-flush" v-for="(txt, key) in recipe_html">
|
||||
<div class="list-group-item bg-light m-0 small"
|
||||
draggable
|
||||
<div class="list-group-item bg-light m-0 small"
|
||||
draggable
|
||||
@dragstart="htmlDragStart($event)"
|
||||
style="display:flex; justify-content:space-between;">
|
||||
[[txt]]
|
||||
style="display:flex; justify-content:space-between;">
|
||||
[[txt]]
|
||||
<i class="fas fa-minus-square" style="cursor:pointer; color:red" @click="$delete(recipe_html, key)" title="{% trans 'Delete Text'%}"></i>
|
||||
</div>
|
||||
</ul>
|
||||
@@ -361,10 +380,10 @@
|
||||
<!-- start of images -->
|
||||
<div v-if="preview_type=='image'">
|
||||
<ul class="list-group list-group-flush" v-for="(img, key) in images">
|
||||
<div class="list-group-item bg-light m-0 small"
|
||||
draggable
|
||||
<div class="list-group-item bg-light m-0 small"
|
||||
draggable
|
||||
@dragstart="imageDragStart($event)"
|
||||
style="display:flex; justify-content:space-between;">
|
||||
style="display:flex; justify-content:space-between;">
|
||||
<img class="card-img" v-bind:src=[[img]] alt="Image">
|
||||
<i class="fas fa-minus-square" style="cursor:pointer; color:red" @click="$delete(images, key)" title="{% trans 'Delete image'%}"></i>
|
||||
</div>
|
||||
|
||||
@@ -16,10 +16,6 @@ from django.http import FileResponse, HttpResponse, JsonResponse
|
||||
from django.shortcuts import redirect, get_object_or_404
|
||||
from django.utils.translation import gettext as _
|
||||
from icalendar import Calendar, Event
|
||||
|
||||
from rest_framework import decorators, viewsets
|
||||
from rest_framework.exceptions import APIException, PermissionDenied
|
||||
|
||||
from recipe_scrapers import scrape_me, WebsiteNotImplementedError, NoSchemaFoundInWildMode
|
||||
from rest_framework import decorators, viewsets
|
||||
from rest_framework.exceptions import APIException, PermissionDenied
|
||||
@@ -34,13 +30,11 @@ from cookbook.helper.ingredient_parser import parse
|
||||
from cookbook.helper.permission_helper import (CustomIsAdmin, CustomIsGuest,
|
||||
CustomIsOwner, CustomIsShare,
|
||||
CustomIsShared, CustomIsUser,
|
||||
|
||||
group_required, share_link_valid)
|
||||
group_required)
|
||||
from cookbook.helper.recipe_html_import import get_recipe_from_source
|
||||
from cookbook.helper.recipe_url_import import get_from_scraper
|
||||
from cookbook.helper.recipe_search import search_recipes
|
||||
from cookbook.helper.recipe_url_import import get_from_html, get_from_scraper, find_recipe_json
|
||||
|
||||
from cookbook.helper.recipe_search import search_recipes
|
||||
from cookbook.helper.recipe_url_import import get_from_scraper
|
||||
from cookbook.models import (CookLog, Food, Ingredient, Keyword, MealPlan,
|
||||
MealType, Recipe, RecipeBook, ShoppingList,
|
||||
ShoppingListEntry, ShoppingListRecipe, Step,
|
||||
|
||||
Reference in New Issue
Block a user