Fix after rebase

This commit is contained in:
smilerz 2021-04-16 11:17:00 -05:00
parent a69fb4922d
commit 2ecc0ab680
12 changed files with 48 additions and 67 deletions

View File

@ -15,8 +15,8 @@ def get_from_scraper(scrape, space):
recipe_json = {}
try:
recipe_json['name'] = scrape.title()
except TypeError:
recipe_json['name'] = parse_name(scrape.title() or scrape.schema.data.get('name') or '')
except (TypeError, AttributeError):
recipe_json['name'] = ''
try:

View File

@ -46,11 +46,12 @@ class CooksIllustrated(AbstractScraper):
def instructions(self):
if not self.recipe:
self.get_recipe()
return "\n".join([self.recipe['whyThisWorks']] +
[
instruction['fields']['content']
for instruction in self.recipe['instructions']
]
return "\n".join(
[self.recipe['whyThisWorks']]
+ [
instruction['fields']['content']
for instruction in self.recipe['instructions']
]
)
def nutrients(self):

View File

@ -13,8 +13,8 @@
<link rel="shortcut icon" type="image/x-icon" href="{% static 'assets/favicon.svg' %}">
<link rel="shortcut icon" href="{% static 'assets/favicon.svg' %}">
<link rel="icon" type="image/png" href="{% static 'assets/.svg' %}" sizes="32x32">
<link rel="icon" type="image/png" href="{% static 'assets/favicon-16x16.png' %}" sizes="16x16" >
<link rel="icon" type="image/png" href="{% static 'assets/favicon-32x32.png' %}" sizes="32x32">
<link rel="icon" type="image/png" href="{% static 'assets/favicon-16x16.png' %}" sizes="16x16">
<link rel="mask-icon" href="{% static 'assets/safari-pinned-tab.svg' %}" color="#161616">
<link rel="apple-touch-icon" href="{% static 'assets/apple-touch-icon.png' %}" sizes="180x180">
@ -24,10 +24,9 @@
<meta name="msapplication-TileImage" content="/mstile-144x144.png">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#161616">
<meta name="msapplication-TileColor" content="#161616">
<meta name="theme-color" content="#ffffff">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#161616">
<meta name="msapplication-TileColor" content="#161616">
<meta name="theme-color" content="#ffffff">
<!-- Bootstrap 4 -->

View File

@ -699,36 +699,13 @@
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')
})
},
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('Bookmarklet not found!') , 'danger')
})
},
deleteBookmarklet: function(id_bkmk) {
this.error = undefined
this.$http.delete("{% url 'api:bookmarkletimport-list' %}" + id_bkmk +"/").then((response) => {
}).catch((err) => {
this.error = err.data
console.log(err)
this.makeToast(gettext('Error'), gettext('There was an error deleting bookmarklet!') + err.bodyText, 'danger')
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')
})
},
loadBookmarklet: function(id_bkmk) {

View File

@ -76,7 +76,8 @@ def test_add(arg, request, u1_s2):
print(r.content)
assert r.status_code == arg[1]
if r.status_code == 201:
assert response['id'] == 1
# id can change when running multiple tests, changed to validate name
assert response['name'] == 'test'
r = c.get(reverse(DETAIL_URL, args={response['id']}))
assert r.status_code == 200
r = u1_s2.get(reverse(DETAIL_URL, args={response['id']}))

View File

@ -128,10 +128,8 @@ ALLRECIPES = {
}
AMERICAS_TEST_KITCHEN = {
"file": [
'americastestkitchen.html',
'cookscountry.html'
],
"file": ['americastestkitchen.html'],
'url': 'http://www.americastestkitchen.com/recipes/1771-pasta-with-chicken-broccoli-and-sun-dried-tomatoes',
"name": "Pasta with Chicken, Broccoli, and Sun-dried Tomatoes",
"description": "This restaurant-chain classic can be as off-putting as a bad horror movie: drab colors, tough meat, and a main character—the pasta—with no bite.",
"servings": 4,
@ -140,13 +138,12 @@ AMERICAS_TEST_KITCHEN = {
"image": "https://res.cloudinary.com/hksqkdlah/image/upload/ar_1:1,c_fill,dpr_2.0,f_auto,fl_lossy.progressive.strip_profile,g_faces:auto,q_auto:low,w_150/33255_sfs-pasta-with-chicken-broccoli-sun-dried-tomatoes-15",
"keywords": [
{
"id": "21",
"text": "main courses"
}
],
"recipeIngredient": [
{
"amount": 4,
"amount": 4.0,
"unit": {
"text": "tablespoons"
},
@ -157,7 +154,7 @@ AMERICAS_TEST_KITCHEN = {
"original": "4 tablespoons unsalted butter"
},
{
"amount": 1,
"amount": 1.0,
"unit": {
"text": "pound"
},
@ -168,7 +165,7 @@ AMERICAS_TEST_KITCHEN = {
"original": "1 pound boneless, skinless chicken breast, trimmed of fat and cut crosswise into 1/4-inch slices"
},
{
"amount": 1,
"amount": 1.0,
"unit": {
"text": "small"
},
@ -190,7 +187,7 @@ AMERICAS_TEST_KITCHEN = {
"original": " Table salt"
},
{
"amount": 6,
"amount": 6.0,
"unit": {
"text": "medium"
},
@ -212,7 +209,7 @@ AMERICAS_TEST_KITCHEN = {
"original": "1/4 teaspoon red pepper flakes"
},
{
"amount": 2,
"amount": 2.0,
"unit": {
"text": "teaspoons"
},
@ -223,7 +220,7 @@ AMERICAS_TEST_KITCHEN = {
"original": "2 teaspoons chopped fresh thyme leaves"
},
{
"amount": 2,
"amount": 2.0,
"unit": {
"text": "teaspoons"
},
@ -234,7 +231,7 @@ AMERICAS_TEST_KITCHEN = {
"original": "2 teaspoons all-purpose flour"
},
{
"amount": 1,
"amount": 1.0,
"unit": {
"text": "cup"
},
@ -245,7 +242,7 @@ AMERICAS_TEST_KITCHEN = {
"original": "1 cup dry white wine"
},
{
"amount": 2,
"amount": 2.0,
"unit": {
"text": "cups"
},
@ -256,7 +253,7 @@ AMERICAS_TEST_KITCHEN = {
"original": "2 cups low-sodium chicken broth"
},
{
"amount": 1,
"amount": 1.0,
"unit": {
"text": "bunch"
},
@ -278,7 +275,7 @@ AMERICAS_TEST_KITCHEN = {
"original": "1/2 pound penne pasta, ziti, cavatappi, or campanelle"
},
{
"amount": 2,
"amount": 2.0,
"unit": {
"text": "ounces"
},
@ -289,7 +286,7 @@ AMERICAS_TEST_KITCHEN = {
"original": "2 ounces grated Asiago cheese(1 cup), plus extra for serving"
},
{
"amount": 1,
"amount": 1.0,
"unit": {
"text": "jar"
},
@ -300,7 +297,7 @@ AMERICAS_TEST_KITCHEN = {
"original": "1 jar oil-packed sun-dried tomato(7 to 8 1/2 ounces), rinsed, patted dry, and cut into 1/4-inch strips (about 1 cup)"
},
{
"amount": 1,
"amount": 1.0,
"unit": {
"text": "tablespoon"
},

View File

@ -60,6 +60,7 @@ urlpatterns = [
path('test2/', views.test2, name='view_test2'),
path('import/', import_export.import_recipe, name='view_import'),
path('import-response/<int:pk>/', import_export.import_response, name='view_import_response'),
path('export/', import_export.export_recipe, name='view_export'),
path('view/recipe/<int:pk>', views.recipe_view, name='view_recipe'),

View File

@ -12,9 +12,8 @@ from django.contrib.auth.models import User
from django.core.exceptions import FieldError, ValidationError
from django.core.files import File
from django.db.models import Q
from django.http import FileResponse, HttpResponse, JsonResponse, HttpResponseRedirect
from django.shortcuts import redirect, render, get_object_or_404
from django.urls import reverse
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

View File

@ -107,3 +107,7 @@ def export_recipe(request):
return render(request, 'export.html', {'form': form})
@group_required('user')
def import_response(request, pk):
return render(request, 'import_response.html', {'pk': pk})

0
manage.py Normal file → Executable file
View File

View File

@ -280,3 +280,5 @@ CORS_ORIGIN_ALLOW_ALL = True
# enable CORS only for bookmarklet api and only for posts, get and options
CORS_URLS_REGEX = r'^/api/bookmarklet-import.*$'
CORS_ALLOW_METHODS = ['GET', 'OPTIONS', 'POST']
# future versions of django will make undeclared default django.db.models.BigAutoField which will force migrations on all models
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

View File

@ -31,8 +31,8 @@ Jinja2==2.11.3
django-webpack-loader==0.7.0
django-js-reverse==0.9.1
django-allauth==0.44.0
recipe-scrapers==12.2.1
recipe-scrapers==12.2.2
django-scopes==1.2.0
pytest==6.2.2
pytest-django==4.1.0
pytest==6.2.3
pytest-django==4.2.0
django-cors-headers==3.7.0