X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/ac5de8695878cb6aabf9161930af189cf5d15316..c32ea85e72f0c061117256319580f935b9419364:/src/cover/forms.py?ds=inline diff --git a/src/cover/forms.py b/src/cover/forms.py index a1ba182d..b7fddfb7 100644 --- a/src/cover/forms.py +++ b/src/cover/forms.py @@ -2,7 +2,7 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from io import BytesIO - +from urllib.request import urlopen from django import forms from django.conf import settings from django.utils.translation import gettext_lazy as _, gettext @@ -10,7 +10,7 @@ from cover.models import Image from django.utils.safestring import mark_safe from PIL import Image as PILImage -from cover.utils import get_import_data, FlickrError, URLOpener +from cover.utils import get_import_data, FlickrError class ImageAddForm(forms.ModelForm): @@ -62,7 +62,8 @@ class ImageAddForm(forms.ModelForm): if not download_url and not uploaded_file: raise forms.ValidationError(gettext('No image specified')) if download_url: - image_data = URLOpener().open(download_url).read() + with urlopen(download_url) as f: + image_data = f.read() width, height = PILImage.open(BytesIO(image_data)).size else: width, height = PILImage.open(uploaded_file.file).size