mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
fixed recipe url import issue on some pages without images
This commit is contained in:
@@ -14,6 +14,7 @@ from django.utils.translation import gettext as _
|
|||||||
from django.utils.translation import ngettext
|
from django.utils.translation import ngettext
|
||||||
from django_tables2 import RequestConfig
|
from django_tables2 import RequestConfig
|
||||||
from PIL import Image, UnidentifiedImageError
|
from PIL import Image, UnidentifiedImageError
|
||||||
|
from requests.exceptions import MissingSchema
|
||||||
|
|
||||||
from cookbook.forms import BatchEditForm, SyncForm
|
from cookbook.forms import BatchEditForm, SyncForm
|
||||||
from cookbook.helper.permission_helper import (group_required,
|
from cookbook.helper.permission_helper import (group_required,
|
||||||
@@ -164,7 +165,7 @@ def import_url(request):
|
|||||||
step.ingredients.add(ingredient)
|
step.ingredients.add(ingredient)
|
||||||
print(ingredient)
|
print(ingredient)
|
||||||
|
|
||||||
if 'image' in data and data['image'] != '':
|
if 'image' in data and data['image'] != '' and data['image'] is not None:
|
||||||
try:
|
try:
|
||||||
response = requests.get(data['image'])
|
response = requests.get(data['image'])
|
||||||
img = Image.open(BytesIO(response.content))
|
img = Image.open(BytesIO(response.content))
|
||||||
@@ -183,6 +184,8 @@ def import_url(request):
|
|||||||
recipe.save()
|
recipe.save()
|
||||||
except UnidentifiedImageError:
|
except UnidentifiedImageError:
|
||||||
pass
|
pass
|
||||||
|
except MissingSchema:
|
||||||
|
pass
|
||||||
|
|
||||||
return HttpResponse(reverse('view_recipe', args=[recipe.pk]))
|
return HttpResponse(reverse('view_recipe', args=[recipe.pk]))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user