-
-
-@cache.never_cache
-def epubs(request):
- """"
- Create a tar archive with all EPUB files, segregated to directories.
- """
-
- temp = tempfile.TemporaryFile()
- archive = tarfile.TarFile(fileobj=temp, mode='w')
-
- for book in models.Book.objects.exclude(epub_file=''):
- archive.add(book.epub_file.path, (u'%s/%s.epub' % (book.get_extra_info_value()['author'], book.slug)).encode('utf-8'))
- archive.close()
-
- response = HttpResponse(content_type='application/tar', mimetype='application/x-tar')
- response['Content-Disposition'] = 'attachment; filename=epubs.tar'
- response['Content-Length'] = temp.tell()
-
- temp.seek(0)
- response.write(temp.read())
- return response