From: Marcin Koziej Date: Mon, 28 May 2012 15:03:00 +0000 (+0200) Subject: FB2 support X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/e883fa899b3df6e047f9e821a7ca81f53a02ddba?ds=sidebyside;hp=--cc FB2 support --- e883fa899b3df6e047f9e821a7ca81f53a02ddba diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 29106b184..f283ccedc 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -346,7 +346,7 @@ class Book(models.Model): cover = models.FileField(_('cover'), upload_to=book_upload_path('png'), null=True, blank=True) - ebook_formats = ['pdf', 'epub', 'mobi', 'txt'] + ebook_formats = ['pdf', 'epub', 'mobi', 'fb2', 'txt'] formats = ebook_formats + ['html', 'xml'] parent = models.ForeignKey('self', blank=True, null=True, related_name='children') @@ -546,6 +546,9 @@ class Book(models.Model): def build_mobi(self, *args, **kwargs): """(Re)builds MOBI.""" return tasks.build_mobi.delay(self.pk, *args, **kwargs) + def build_fb2(self, *args, **kwargs): + """(Re)build FB2""" + return tasks.build_fb2.delay(self.pk, *args, **kwargs) def build_txt(self, *args, **kwargs): """(Re)builds TXT.""" return tasks.build_txt.delay(self.pk, *args, **kwargs) @@ -603,7 +606,7 @@ class Book(models.Model): @classmethod def from_text_and_meta(cls, raw_file, book_info, overwrite=False, - build_epub=True, build_txt=True, build_pdf=True, build_mobi=True, + build_epub=True, build_txt=True, build_pdf=True, build_mobi=True, build_fb2=True, search_index=True, search_index_tags=True, search_index_reuse=False): # check for parts before we do anything @@ -673,6 +676,9 @@ class Book(models.Model): if not settings.NO_BUILD_MOBI and build_mobi: book.build_mobi() + if not settings.NO_BUILD_FB2 and build_fb2: + book.build_fb2() + if not settings.NO_SEARCH_INDEX and search_index: book.search_index(index_tags=search_index_tags, reuse_index=search_index_reuse) #index_book.delay(book.id, book_info) diff --git a/apps/catalogue/tasks.py b/apps/catalogue/tasks.py index 6d19ee18a..d0437820c 100755 --- a/apps/catalogue/tasks.py +++ b/apps/catalogue/tasks.py @@ -73,7 +73,7 @@ def build_epub(book_id): from catalogue.utils import remove_zip epub = Book.objects.get(pk=book_id).wldocument().as_epub() - # Save the file in new instance. Building MOBI takes time and we don't want + # Save the file in new instance. Building EPUB takes time and we don't want # to overwrite any interim changes. book = Book.objects.get(id=book_id) book.epub_file.save('%s.epub' % book.slug, @@ -101,6 +101,24 @@ def build_mobi(book_id): remove_zip(settings.ALL_MOBI_ZIP) +@task(ignore_result=True, rate_limit=settings.CATALOGUE_MOBI_RATE_LIMIT) +def build_fb2(book_id, *args, **kwargs): + """(Re)builds the MOBI file for a book.""" + from django.core.files import File + from catalogue.models import Book + from catalogue.utils import remove_zip + + fb2 = Book.objects.get(pk=book_id).wldocument().as_fb2() + # Save the file in new instance. Building FB2 takes time and we don't want + # to overwrite any interim changes. + book = Book.objects.get(id=book_id) + book.fb2_file.save('%s.fb2' % book.slug, + File(open(fb2.get_filename()))) + + # remove zip with all mobi files + remove_zip(settings.ALL_FB2_ZIP) + + @task(rate_limit=settings.CATALOGUE_CUSTOMPDF_RATE_LIMIT) def build_custom_pdf(book_id, customizations, file_name): """Builds a custom PDF file.""" diff --git a/apps/catalogue/templates/catalogue/book_short.html b/apps/catalogue/templates/catalogue/book_short.html index d9b5b7689..6942bc499 100644 --- a/apps/catalogue/templates/catalogue/book_short.html +++ b/apps/catalogue/templates/catalogue/book_short.html @@ -95,6 +95,9 @@ {% if book.mobi_file %} MOBI {% trans "for Kindle" %} {% endif %} + {% if book.fb2_file %} + FB2 {% trans "FictionBook" %} + {% endif %} {% if book.txt_file %} TXT {% trans "for advanced usage" %} {% endif %} diff --git a/lib/librarian b/lib/librarian index fed2483b3..bd2ad2356 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit fed2483b39e23ecd91ec2d04495a4caac208e94c +Subproject commit bd2ad2356d916f72762de867890b5d176830f73b diff --git a/wolnelektury/settings/custom.py b/wolnelektury/settings/custom.py index e059b8f9a..76aa58117 100644 --- a/wolnelektury/settings/custom.py +++ b/wolnelektury/settings/custom.py @@ -7,15 +7,18 @@ MAX_TAG_LIST = 6 NO_SEARCH_INDEX = False NO_BUILD_EPUB = False NO_BUILD_TXT = False +NO_BUILD_FB2 = False # You'll need XeLaTeX to generate PDF files. NO_BUILD_PDF = True NO_CUSTOM_PDF = True # You'll need Calibre installed to generate MOBI files. NO_BUILD_MOBI = True + ALL_EPUB_ZIP = 'wolnelektury_pl_epub' ALL_PDF_ZIP = 'wolnelektury_pl_pdf' ALL_MOBI_ZIP = 'wolnelektury_pl_mobi' +ALL_FB2_ZIP = 'wolnelektury_pl_fb2' CATALOGUE_DEFAULT_LANGUAGE = 'pol' PUBLISH_PLAN_FEED = 'http://redakcja.wolnelektury.pl/documents/track/editor-proofreading/?published=false'