def build_custom_pdf(book_id, customizations, file_name, waiter_id=None): """Builds a custom PDF file.""" try: from django.core.files import File from django.core.files.storage import DefaultStorage from catalogue.models import Book task_logger.info(DefaultStorage().path(file_name)) if not DefaultStorage().exists(file_name): kwargs = { 'cover': True, } if 'nocover' in customizations: kwargs['cover'] = False customizations.remove('nocover') wldoc = Book.objects.get(pk=book_id).wldocument() pdf = wldoc.as_pdf(customizations=customizations, morefloats=settings.LIBRARIAN_PDF_MOREFLOATS, ilustr_path=gallery_path( wldoc.book_info.url.slug), **kwargs) DefaultStorage().save(file_name, File(open(pdf.get_filename()))) finally: if waiter_id is not None: WaitedFile.objects.filter(pk=waiter_id).delete()
def build_custom_pdf(book_id, customizations, file_name, waiter_id=None): """Builds a custom PDF file.""" try: from django.core.files import File from django.core.files.storage import DefaultStorage from catalogue.models import Book task_logger.info(DefaultStorage().path(file_name)) if not DefaultStorage().exists(file_name): kwargs = { 'cover': True, } if 'nocover' in customizations: kwargs['cover'] = False customizations.remove('nocover') wldoc = Book.objects.get(pk=book_id).wldocument() pdf = wldoc.as_pdf( customizations=customizations, morefloats=settings.LIBRARIAN_PDF_MOREFLOATS, ilustr_path=gallery_path(wldoc.book_info.url.slug), **kwargs) DefaultStorage().save(file_name, File(open(pdf.get_filename(), 'rb'))) finally: if waiter_id is not None: WaitedFile.objects.filter(pk=waiter_id).delete()
def transform(wldoc, fieldfile): return wldoc.as_mobi(cover=True, ilustr_path=gallery_path(wldoc.book_info.url.slug))
def transform(wldoc, fieldfile): return wldoc.as_pdf(morefloats=settings.LIBRARIAN_PDF_MOREFLOATS, cover=True, ilustr_path=gallery_path(wldoc.book_info.url.slug))
def gallery_path(self): return gallery_path(self.slug)
def transform(wldoc, fieldfile): return wldoc.as_mobi(cover=True, ilustr_path=gallery_path( wldoc.book_info.url.slug))