if form.is_valid():
formats = form.cleaned_data['formats']
if len(formats) == 0:
- formats = ['pdf', 'epub', 'odt', 'txt']
+ formats = ['pdf', 'epub', 'mobi', 'odt', 'txt']
# Create a ZIP archive
temp = tempfile.TemporaryFile()
if 'pdf' in formats and book.pdf_file:
filename = book.pdf_file.path
archive.write(filename, str('%s.pdf' % book.slug))
+ if 'mobi' in formats and book.mobi_file:
+ filename = book.mobi_file.path
+ archive.write(filename, str('%s.mobi' % book.slug))
if book.root_ancestor not in already and 'epub' in formats and book.root_ancestor.epub_file:
filename = book.root_ancestor.epub_file.path
archive.write(filename, str('%s.epub' % book.root_ancestor.slug))
"""
shelf = get_object_or_404(models.Tag, slug=shelf, category='set')
- formats = {'pdf': False, 'epub': False, 'odt': False, 'txt': False}
+ formats = {'pdf': False, 'epub': False, 'mobi': False, 'odt': False, 'txt': False}
for book in collect_books(models.Book.tagged.with_all(shelf)):
if book.pdf_file:
formats['pdf'] = True
if book.root_ancestor.epub_file:
formats['epub'] = True
+ if book.mobi_file:
+ formats['mobi'] = True
if book.txt_file:
formats['txt'] = True
for format in ('odt',):
def download_zip(request, format, slug):
url = None
- if format == 'pdf':
- url = models.Book.zip_pdf()
- elif format == 'epub':
- url = models.Book.zip_epub()
+ if format in ('pdf', 'epub', 'mobi'):
+ url = models.Book.zip_format(format)
elif format == 'audiobook' and slug is not None:
book = models.Book.objects.get(slug=slug)
url = book.zip_audiobooks()
else:
raise Http404('No format specified for zip package')
- return HttpResponseRedirect(urlquote_plus(url, safe='/?='))
+ return HttpResponseRedirect(urlquote_plus(settings.MEDIA_URL + url, safe='/?='))