shelf info + opds fix
[wolnelektury.git] / apps / catalogue / tasks.py
index 6d19ee1..d043782 100755 (executable)
@@ -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()
     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,
     # 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)
 
 
     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."""
 @task(rate_limit=settings.CATALOGUE_CUSTOMPDF_RATE_LIMIT)
 def build_custom_pdf(book_id, customizations, file_name):
     """Builds a custom PDF file."""