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')
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)
@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
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)
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,
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."""
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'