X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d82dc4a324b95f4cdfa724eed6b6181342f48b02..96a96c16513a98378e2f75ead26a22c358795182:/apps/catalogue/migrations/0021_build_covers.py diff --git a/apps/catalogue/migrations/0021_build_covers.py b/apps/catalogue/migrations/0021_build_covers.py index 126417d5f..319decb18 100644 --- a/apps/catalogue/migrations/0021_build_covers.py +++ b/apps/catalogue/migrations/0021_build_covers.py @@ -10,15 +10,20 @@ class Migration(DataMigration): "Write your forwards methods here." from StringIO import StringIO from django.core.files.base import ContentFile + from librarian import ValidationError from librarian.cover import WLCover from librarian.dcparser import BookInfo - for book in orm.Book.objects.filter(cover=''): - book_info = BookInfo.from_file(book.xml_file.path) - cover = WLCover(book_info).image() - imgstr = StringIO() - cover.save(imgstr, 'png') - book.cover.save('book/png/%s.png' % book.slug, + for book in orm.Book.objects.filter(cover=None): + try: + book_info = BookInfo.from_file(book.xml_file.path) + except ValidationError: + pass + else: + cover = WLCover(book_info).image() + imgstr = StringIO() + cover.save(imgstr, 'png') + book.cover.save('book/png/%s.png' % book.slug, ContentFile(imgstr.getvalue()))