X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/3756a9d667b0207137d004f2bb5a7731b671073c..69191eddb9e4221d964a7e5b044ff7c5dfe38315:/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()))