From: Guillaume Pellerin Date: Tue, 24 Feb 2015 12:21:21 +0000 (+0100) Subject: epub: add audio items and related images X-Git-Tag: 1.6a^2~19^2~7 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=8ad8e67d94981d51849218adf781726fa1b117e7;p=telemeta.git epub: add audio items and related images --- diff --git a/telemeta/static/telemeta/css/telemeta_epub.css b/telemeta/static/telemeta/css/telemeta_epub.css index f4d3b694..3cd6cb6e 100644 --- a/telemeta/static/telemeta/css/telemeta_epub.css +++ b/telemeta/static/telemeta/css/telemeta_epub.css @@ -10,6 +10,14 @@ h2 { font-weight: 200; } + +h3 { + text-align: left; + font-weight: 1em; + margin-top: 0px; +} + + ol { list-style-type: none; } diff --git a/telemeta/templates/telemeta/collection_epub.html b/telemeta/templates/telemeta/collection_epub.html index 0fa92b5f..d717a60b 100644 --- a/telemeta/templates/telemeta/collection_epub.html +++ b/telemeta/templates/telemeta/collection_epub.html @@ -1,8 +1,20 @@ {% for item in collection.items.all %} -

- {{ item.title }} -
-

+ +
+

{{ item.title }}

+
+ +
+
+ + {% for image in item.related.all %} + {% if 'image' in image.mime_type %} +
+ +
+ {% endif %} + {% endfor %} + {% endfor %} diff --git a/telemeta/templates/telemeta/collection_epub_urls.html b/telemeta/templates/telemeta/collection_epub_urls.html new file mode 100644 index 00000000..0fa92b5f --- /dev/null +++ b/telemeta/templates/telemeta/collection_epub_urls.html @@ -0,0 +1,8 @@ + +{% for item in collection.items.all %} +

+ {{ item.title }} +
+

+{% endfor %} diff --git a/telemeta/views/resource.py b/telemeta/views/resource.py index 50feeb26..4e99bf89 100644 --- a/telemeta/views/resource.py +++ b/telemeta/views/resource.py @@ -349,7 +349,6 @@ class ResourceEditView(ResourceSingleMixin, UpdateWithInlinesView): return super(ResourceEditView, self).dispatch(*args, **kwargs) - class CorpusEpubView(View): model = MediaCorpus @@ -379,13 +378,23 @@ class CorpusEpubView(View): book.add_author(corpus.descriptions) # add cover image - for media in corpus.related.all(): - if 'cover' in media.title or 'Cover' in media.title: - book.set_cover("cover.jpg", open(media.file.path, 'r').read()) - break + # for media in corpus.related.all(): + # if 'cover' in media.title or 'Cover' in media.title: + # book.set_cover("cover.jpg", open(media.file.path, 'r').read()) + # break chapters = [] for collection in corpus.children.all(): + for item in collection.items.all(): + if item.file: + audio = open(item.file.path, 'r') + epub_item = epub.EpubItem(file_name=str(item.file), content=audio.read()) + book.add_item(epub_item) + for related in item.related.all(): + if 'image' in related.mime_type: + image = open(related.file.path, 'r') + epub_item = epub.EpubItem(file_name=str(related.file), content=image.read()) + book.add_item(epub_item) context = {'collection': collection, 'site': site} c = epub.EpubHtml(title=collection.title, file_name=collection.code + '.xhtml', lang='fr') c.content = render_to_string(collection_template, context) @@ -401,7 +410,7 @@ class CorpusEpubView(View): book.toc = (( chapters )) - # add navigation files + # add navigation files book.add_item(epub.EpubNcx()) book.add_item(epub.EpubNav()) @@ -420,7 +429,7 @@ class CorpusEpubView(View): epub.write_epub(filename, book, {}) epub_file = open(filename, 'r') - response = StreamingHttpResponse(epub_file.read(), content_type='application/epub+zip') + response = HttpResponse(epub_file.read(), content_type='application/epub+zip') response['Content-Disposition'] = "attachment; filename=%s.%s" % \ (collection.code, 'epub') return response