- def zip_epub():
- books = Book.objects.all()
-
- paths = filter(lambda x: x is not None,
- map(lambda b: b.epub_file and b.epub_file.path or None, books))
- if settings.USE_CELERY:
- result = create_zip_task.delay(paths, settings.ALL_EPUB_ZIP)
- return result.wait()
- else:
- result = create_zip_task(paths, settings.ALL_EPUB_ZIP)
- return result
-
- @staticmethod
- def zip_pdf():
- books = Book.objects.all()
-
- paths = filter(lambda x: x is not None,
- map(lambda b: b.pdf_file and b.pdf_file.path or None, books))
- if settings.USE_CELERY:
- result = create_zip_task.delay(paths, settings.ALL_PDF_ZIP)
- return result.wait()
- else:
- result = create_zip_task(paths, settings.ALL_PDF_ZIP)
- return result
-
- @staticmethod
- def zip_mobi():
- books = Book.objects.all()
-
- paths = filter(lambda x: x is not None,
- map(lambda b: b.mobi_file and b.mobi_file.path or None, books))
- result = create_zip_task.delay(paths, settings.ALL_MOBI_ZIP)
- return settings.MEDIA_URL + result.wait()
+ def zip_format(format_):
+ def pretty_file_name(book):
+ return "%s/%s.%s" % (
+ b.get_extra_info_value()['author'],
+ b.slug,
+ format_)
+
+ field_name = "%s_file" % format_
+ books = Book.objects.filter(parent=None).exclude(**{field_name: ""})
+ paths = [(pretty_file_name(b), getattr(b, field_name).path)
+ for b in books]
+ result = create_zip.delay(paths,
+ getattr(settings, "ALL_%s_ZIP" % format_.upper()))
+ return result.wait()