Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
 def transform(wldoc, fieldfile):
     return wldoc.as_mobi(cover=True, ilustr_path=gallery_path(wldoc.book_info.url.slug))
Ejemplo n.º 4
0
 def transform(wldoc, fieldfile):
     return wldoc.as_pdf(morefloats=settings.LIBRARIAN_PDF_MOREFLOATS, cover=True,
                         ilustr_path=gallery_path(wldoc.book_info.url.slug))
Ejemplo n.º 5
0
 def gallery_path(self):
     return gallery_path(self.slug)
Ejemplo n.º 6
0
 def transform(wldoc, fieldfile):
     return wldoc.as_mobi(cover=True,
                          ilustr_path=gallery_path(
                              wldoc.book_info.url.slug))
Ejemplo n.º 7
0
 def transform(wldoc, fieldfile):
     return wldoc.as_pdf(morefloats=settings.LIBRARIAN_PDF_MOREFLOATS,
                         cover=True,
                         ilustr_path=gallery_path(wldoc.book_info.url.slug))