コード例 #1
0
ファイル: tasks.py プロジェクト: learner9753/wolnelektury
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()
コード例 #2
0
ファイル: tasks.py プロジェクト: fnp/wolnelektury
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()
コード例 #3
0
 def transform(wldoc, fieldfile):
     return wldoc.as_mobi(cover=True, ilustr_path=gallery_path(wldoc.book_info.url.slug))
コード例 #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))
コード例 #5
0
ファイル: book.py プロジェクト: learner9753/wolnelektury
 def gallery_path(self):
     return gallery_path(self.slug)
コード例 #6
0
 def transform(wldoc, fieldfile):
     return wldoc.as_mobi(cover=True,
                          ilustr_path=gallery_path(
                              wldoc.book_info.url.slug))
コード例 #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))