mods = {'item': MediaItem, 'collection': MediaCollection,
'corpus': MediaCorpus, 'fonds': MediaFonds, 'marker': MediaItemMarker, }
-# TOOLS
+
+class TelemetaBaseMixin(object):
+
+ cache_data = TelemetaCache(settings.TELEMETA_DATA_CACHE_DIR)
+ cache_export = TelemetaCache(settings.TELEMETA_EXPORT_CACHE_DIR)
+
class FixedFileWrapper(FileWrapper):
def __iter__(self):
import timeside.core
-class ItemBaseMixin(object):
+class ItemBaseMixin(TelemetaBaseMixin):
graphers = timeside.core.processor.processors(timeside.core.api.IGrapher)
decoders = timeside.core.processor.processors(timeside.core.api.IDecoder)
encoders = timeside.core.processor.processors(timeside.core.api.IEncoder)
analyzers = timeside.core.processor.processors(timeside.core.api.IAnalyzer)
value_analyzers = timeside.core.processor.processors(timeside.core.api.IValueAnalyzer)
- cache_data = TelemetaCache(settings.TELEMETA_DATA_CACHE_DIR)
- cache_export = TelemetaCache(settings.TELEMETA_EXPORT_CACHE_DIR)
export_enabled = getattr(settings, 'TELEMETA_DOWNLOAD_ENABLED', True)
export_formats = getattr(settings, 'TELEMETA_DOWNLOAD_FORMATS', ('mp3', 'wav'))
return os.sep.join(new_path)
-class CorpusEpubView(View):
+class CorpusEpubView(TelemetaBaseMixin, View):
+ "Download corpus data embedded in an EPUB3 file"
model = MediaCorpus
return MediaCorpus.objects.get(public_id=self.kwargs['public_id'])
def get(self, request, *args, **kwargs):
- """
- Stream an Epub file of collection data
- """
from collections import OrderedDict
from ebooklib import epub
from django.template.loader import render_to_string
book.spine = chapters
# create epub file
- filename = '/tmp/test.epub'
+ epub_name = corpus.code + '.epub'
+ path = self.cache_data.dir + os.sep + epub_name
epub.write_epub(filename, book, {})
epub_file = open(filename, 'rb')
response = HttpResponse(epub_file.read(), content_type='application/epub+zip')
- response['Content-Disposition'] = "attachment; filename=%s.%s" % \
- (collection.code, 'epub')
+ response['Content-Disposition'] = "attachment; filename=%s" % epub_name
+
return response
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(CorpusEpubView, self).dispatch(*args, **kwargs)
+