From: Jan Szejko Date: Fri, 16 Dec 2016 12:15:46 +0000 (+0100) Subject: images in epub/mobi X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/22b2835ad2c19802139e21aec067701fc01cb013 images in epub/mobi --- diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index b1b2730f..c1ae288f 100755 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@ -31,8 +31,9 @@ class Book(models.Model): gallery = models.CharField(_('scan gallery name'), max_length=255, blank=True) project = models.ForeignKey(Project, null=True) - #wl_slug = models.CharField(_('title'), max_length=255, null=True, db_index=True, editable=False) - parent = models.ForeignKey('self', null=True, blank=True, verbose_name=_('parent'), related_name="children", editable=False) + # wl_slug = models.CharField(_('title'), max_length=255, null=True, db_index=True, editable=False) + parent = models.ForeignKey( + 'self', null=True, blank=True, verbose_name=_('parent'), related_name="children", editable=False) parent_number = models.IntegerField(_('parent number'), null=True, blank=True, db_index=True, editable=False) # Cache @@ -55,7 +56,6 @@ class Book(models.Model): verbose_name = _('book') verbose_name_plural = _('books') - # Representing # ============ @@ -79,7 +79,10 @@ class Book(models.Model): @models.permalink def get_absolute_url(self): - return ("catalogue_book", [self.slug]) + return "catalogue_book", [self.slug] + + def gallery_path(self): + return os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, self.gallery) def correct_about(self): return "http://%s%s" % ( diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 5f203808..564af626 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -252,7 +252,7 @@ def book_pdf(request, slug): # TODO: move to celery doc = book.wldocument() # TODO: error handling - pdf_file = doc.as_pdf(cover=True, ilustr_path=os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, book.gallery)) + pdf_file = doc.as_pdf(cover=True, ilustr_path=book.gallery_path()) from catalogue.ebook_utils import serve_file return serve_file(pdf_file.get_filename(), book.slug + '.pdf', 'application/pdf') @@ -267,7 +267,7 @@ def book_epub(request, slug): # TODO: move to celery doc = book.wldocument() # TODO: error handling - epub = doc.as_epub().get_string() + epub = doc.as_epub(ilustr_path=book.gallery_path()).get_string() response = HttpResponse(mimetype='application/epub+zip') response['Content-Disposition'] = 'attachment; filename=%s' % book.slug + '.epub' response.write(epub) diff --git a/lib/librarian b/lib/librarian index 2f704d22..3b819de1 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit 2f704d22ddbb461e0c84d709429a9a5dacfa00ed +Subproject commit 3b819de15c20bb071296a34ba25a3c4ae9a54cae