mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
@@ -69,8 +69,10 @@ def find_recipe_json(ld_json, url):
|
|||||||
if 'recipeIngredient' in ld_json:
|
if 'recipeIngredient' in ld_json:
|
||||||
# some pages have comma separated ingredients in a single array entry
|
# some pages have comma separated ingredients in a single array entry
|
||||||
if (len(ld_json['recipeIngredient']) == 1
|
if (len(ld_json['recipeIngredient']) == 1
|
||||||
and len(ld_json['recipeIngredient'][0]) > 30):
|
and type(ld_json['recipeIngredient']) == list):
|
||||||
ld_json['recipeIngredient'] = ld_json['recipeIngredient'][0].split(',') # noqa: E501
|
ld_json['recipeIngredient'] = ld_json['recipeIngredient'][0].split(',') # noqa: E501
|
||||||
|
elif type(ld_json['recipeIngredient']) == str:
|
||||||
|
ld_json['recipeIngredient'] = ld_json['recipeIngredient'].split(',')
|
||||||
|
|
||||||
for x in ld_json['recipeIngredient']:
|
for x in ld_json['recipeIngredient']:
|
||||||
if '\n' in x:
|
if '\n' in x:
|
||||||
@@ -223,6 +225,8 @@ def find_recipe_json(ld_json, url):
|
|||||||
if 'recipeYield' in ld_json:
|
if 'recipeYield' in ld_json:
|
||||||
if type(ld_json['recipeYield']) == str:
|
if type(ld_json['recipeYield']) == str:
|
||||||
ld_json['servings'] = int(re.findall(r'\b\d+\b', ld_json['recipeYield'])[0])
|
ld_json['servings'] = int(re.findall(r'\b\d+\b', ld_json['recipeYield'])[0])
|
||||||
|
elif type(ld_json['recipeYield']) == list:
|
||||||
|
ld_json['servings'] = int(re.findall(r'\b\d+\b', ld_json['recipeYield'][0])[0])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from cookbook.models import Keyword
|
|||||||
from cookbook.tests.views.test_views import TestViews
|
from cookbook.tests.views.test_views import TestViews
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
|
||||||
class TestApiKeyword(TestViews):
|
class TestApiKeyword(TestViews):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -63,6 +62,26 @@ class TestApiKeyword(TestViews):
|
|||||||
self.assertEqual(r.status_code, 200)
|
self.assertEqual(r.status_code, 200)
|
||||||
self.assertEqual(response['name'], 'new')
|
self.assertEqual(response['name'], 'new')
|
||||||
|
|
||||||
|
def test_keyword_add(self):
|
||||||
|
r = self.user_client_1.post(
|
||||||
|
reverse('api:keyword-list'),
|
||||||
|
{'name': 'test'},
|
||||||
|
content_type='application/json'
|
||||||
|
)
|
||||||
|
response = json.loads(r.content)
|
||||||
|
self.assertEqual(r.status_code, 201)
|
||||||
|
self.assertEqual(response['name'], 'test')
|
||||||
|
|
||||||
|
def test_keyword_add_duplicate(self):
|
||||||
|
r = self.user_client_1.post(
|
||||||
|
reverse('api:keyword-list'),
|
||||||
|
{'name': self.keyword_1.name},
|
||||||
|
content_type='application/json'
|
||||||
|
)
|
||||||
|
response = json.loads(r.content)
|
||||||
|
self.assertEqual(r.status_code, 201)
|
||||||
|
self.assertEqual(response['name'], {self.keyword_1.name})
|
||||||
|
|
||||||
def test_keyword_delete(self):
|
def test_keyword_delete(self):
|
||||||
r = self.user_client_1.delete(
|
r = self.user_client_1.delete(
|
||||||
reverse(
|
reverse(
|
||||||
|
|||||||
@@ -134,8 +134,7 @@ def import_url(request):
|
|||||||
recipe.steps.add(step)
|
recipe.steps.add(step)
|
||||||
|
|
||||||
for kw in data['keywords']:
|
for kw in data['keywords']:
|
||||||
if kw['id'] != "null" \
|
if k := Keyword.objects.filter(name=kw['text']).first():
|
||||||
and (k := Keyword.objects.filter(id=kw['id']).first()):
|
|
||||||
recipe.keywords.add(k)
|
recipe.keywords.add(k)
|
||||||
elif data['all_keywords']:
|
elif data['all_keywords']:
|
||||||
k = Keyword.objects.create(name=kw['text'])
|
k = Keyword.objects.create(name=kw['text'])
|
||||||
|
|||||||
Reference in New Issue
Block a user