# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from io import BytesIO
+from urllib.request import urlopen
from django.core.files.base import ContentFile
from django.core.files.storage import FileSystemStorage
from django.db import models
from librarian.dcparser import BookInfo
from librarian.meta.types.person import Person
from librarian.cover import make_cover
-from cover.utils import URLOpener
class OverwriteStorage(FileSystemStorage):
download_url = models.URLField(max_length=4096, unique=True, verbose_name=_('image download URL'), null=True, blank=True)
file = models.ImageField(
upload_to='cover/image',
+ max_length=1024,
storage=OverwriteStorage(),
verbose_name=_('file')
)
@receiver(post_save, sender=Image)
def download_image(sender, instance, **kwargs):
if instance.pk and not instance.file:
- t = URLOpener().open(instance.download_url).read()
+ t = urlopen(instance.download_url).read()
instance.file.save("%d.jpg" % instance.pk, ContentFile(t))