X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d82dc4a324b95f4cdfa724eed6b6181342f48b02..f2056dbaafa8f6a5bf72ef25ecf77060693ba35d:/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()))