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."""