diff --git a/cookbook/helper/recipe_url_import.py b/cookbook/helper/recipe_url_import.py index 6efa82e7a..3f74d97a4 100644 --- a/cookbook/helper/recipe_url_import.py +++ b/cookbook/helper/recipe_url_import.py @@ -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: diff --git a/cookbook/helper/scrapers/cooksillustrated.py b/cookbook/helper/scrapers/cooksillustrated.py index 3164856d9..c59d25c30 100644 --- a/cookbook/helper/scrapers/cooksillustrated.py +++ b/cookbook/helper/scrapers/cooksillustrated.py @@ -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): diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index 876663833..b0b49cfb1 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -13,8 +13,8 @@ - - + + @@ -24,10 +24,9 @@ - - - - + + + diff --git a/cookbook/templates/url_import.html b/cookbook/templates/url_import.html index fdb6e8e1c..0082a38ed 100644 --- a/cookbook/templates/url_import.html +++ b/cookbook/templates/url_import.html @@ -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) { diff --git a/cookbook/tests/api/test_api_recipe.py b/cookbook/tests/api/test_api_recipe.py index 2591c147c..f68db563b 100644 --- a/cookbook/tests/api/test_api_recipe.py +++ b/cookbook/tests/api/test_api_recipe.py @@ -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']})) diff --git a/cookbook/tests/other/_recipes.py b/cookbook/tests/other/_recipes.py index a5958ae57..5587483ea 100644 --- a/cookbook/tests/other/_recipes.py +++ b/cookbook/tests/other/_recipes.py @@ -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" }, diff --git a/cookbook/urls.py b/cookbook/urls.py index f26ce8b4a..d9ab12e83 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -60,6 +60,7 @@ urlpatterns = [ path('test2/', views.test2, name='view_test2'), path('import/', import_export.import_recipe, name='view_import'), + path('import-response//', import_export.import_response, name='view_import_response'), path('export/', import_export.export_recipe, name='view_export'), path('view/recipe/', views.recipe_view, name='view_recipe'), diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 9dcfef7a6..994b3811f 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -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 diff --git a/cookbook/views/import_export.py b/cookbook/views/import_export.py index 365b30def..d0b6a1150 100644 --- a/cookbook/views/import_export.py +++ b/cookbook/views/import_export.py @@ -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}) diff --git a/manage.py b/manage.py old mode 100644 new mode 100755 diff --git a/recipes/settings.py b/recipes/settings.py index dba42e66f..791aa3c43 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -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' diff --git a/requirements.txt b/requirements.txt index 7f9d7fb5a..f4bbe4450 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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