]> git.parisson.com Git - telemeta.git/commitdiff
improve epub views and import
authorGuillaume Pellerin <yomguy@parisson.com>
Fri, 22 May 2015 13:03:36 +0000 (15:03 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Fri, 22 May 2015 13:03:36 +0000 (15:03 +0200)
telemeta/locale
telemeta/management/commands/telemeta-import-corpus-from-dir.py
telemeta/templates/telemeta/inc/epub_collection.html
telemeta/templates/telemeta/inc/epub_preamble.html
telemeta/views/epub.py

index c5786d32a14a841469db2588092390073b8d0688..f27f2cf6cd500e0a6d8e1e6511ed1a9e04d66e44 160000 (submodule)
@@ -1 +1 @@
-Subproject commit c5786d32a14a841469db2588092390073b8d0688
+Subproject commit f27f2cf6cd500e0a6d8e1e6511ed1a9e04d66e44
index 925a621741f28ec3183dd8c9de5700a664c0bc8a..c6322eb546b07d40e6650437fabd3537960ee54b 100644 (file)
@@ -85,6 +85,17 @@ class Command(BaseCommand):
         cleanup_dir(self.source_dir)
         chapters = os.listdir(self.source_dir)
 
+        corpus_name = os.path.split(root_dir)[-1]
+        corpus_id = slugify(unicode(corpus_name))
+
+        cc = MediaCorpus.objects.filter(code=corpus_id)
+        if cc:
+            corpus = cc[0]
+        else:
+            corpus = MediaCorpus(code=corpus_id)
+            corpus.title = corpus_name
+            corpus.save()
+
         for chapter in chapters:
             chapter_dir = os.path.join(self.source_dir, chapter)
             metadata = {}
@@ -128,21 +139,10 @@ class Command(BaseCommand):
 
                         item_name = root_list[-1]
                         collection_name = root_list[-2]
-                        corpus_name = root_list[-3]
                         data = metadata[item_name]
 
-                        corpus_id = slugify(unicode(corpus_name))
                         collection_id = corpus_id + '_' + slugify(unicode(collection_name))
                         item_id = collection_id + '_' + slugify(unicode(item_name))
-
-                        cc = MediaCorpus.objects.filter(code=corpus_id)
-                        if cc:
-                            corpus = cc[0]
-                        else:
-                            corpus = MediaCorpus(code=corpus_id)
-                            corpus.title = corpus_name
-                            corpus.save()
-
                         collection_title = collection_name.replace('_', ' ') + ' - ' + chapter_title
                         print collection_title
                         cc = MediaCollection.objects.filter(code=collection_id, title=collection_title)
index 8df56cac55bd1eb0ddffd3360953562ab99caa68..4f0cbf01396a8d4ed54511be7acde231b06bee5d 100644 (file)
@@ -13,6 +13,7 @@
    <audio class="item-player" src="{{ item.file }}" controls="controls"></audio>
   </div>
 
+  {% if item.related.all %}
   {% for image in item.related.all %}
     {% if 'image' in image.mime_type %}
        <div class="item-image">
        </div>
     {% endif %}
    {% endfor %}
+  {% else %}
+   <div class="item-image">
+        <img src="{{ default_image }}"/>
+   </div>
+  {% endif %}
+
 
 </div>
 {% endfor %}
index d901b11c34041cf3ac1847aa080c6e66b1330fae..96f3402812b2fe0dd223daf7d646d59701f72388 100644 (file)
@@ -5,16 +5,16 @@
 
 <h2>{% trans 'Preamble' %}</h2>
 
-<p>Cet AudioBook est destiné à la lecture des sons présenté dans le livre "Écoute musicale et acoustique" de Michèle Castellengo édité aux éditions Eyrolles.</p>
+<p>Ce livre contient les sons présentés dans le livre "Écoute musicale et acoustique" de Michèle Castellengo édité aux éditions Eyrolles.</p>
 
 <p>
-Conception et réalisation: Eyrolles / Parisson
+Copyright (c) 2015 Michèle Castellengo<br/>
+Édition (e) 2015 Eyrolles<br/>
+Publication (p) 2015 Parisson<br/>
 </p>
 
 <p>
-Copyright (C) 2015 Michèle Castellengo<br/>
-Édition (E) 2015 Eyrolles<br/>
-Publication (P) 2015 Parisson<br/>
+Conception et réalisation : Eyrolles / Parisson
 </p>
 
 <!--
index bf64c0baab5bc1cc7dc490f25b03434fcaf3f9ab..ab48c2d114ff272414a1daa3b08695f9aa2731d8 100644 (file)
@@ -45,6 +45,7 @@ class BaseEpubMixin(TelemetaBaseMixin):
 
     local_path = os.path.dirname(__file__)
     css = os.sep.join([local_path, '..', 'static', 'telemeta', 'css', 'telemeta_epub.css'])
+    default_image = os.sep.join([local_path, '..', 'static', 'telemeta', 'images', 'cul_de_lampe.jpg'])
     template = os.sep.join([local_path, '..', 'templates', 'telemeta', 'inc', 'epub_collection.html'])
     template_preamble = os.sep.join([local_path, '..', 'templates', 'telemeta', 'inc', 'epub_preamble.html'])
 
@@ -53,6 +54,7 @@ class BaseEpubMixin(TelemetaBaseMixin):
         self.corpus = corpus
         site = Site.objects.get_current()
         self.chapters = []
+        default_image_added = False
 
         if not collection:
             self.filename = self.corpus.code
@@ -65,7 +67,7 @@ class BaseEpubMixin(TelemetaBaseMixin):
 
         # add metadata
         self.book.set_identifier(corpus.public_id)
-        #self.book.set_title(corpus.title + ' - ' + collection.title)
+        self.book.set_title(corpus.title + ' - ' + collection.title)
         self.book.set_language('fr')
         self.book.add_author(corpus.descriptions)
 
@@ -74,8 +76,17 @@ class BaseEpubMixin(TelemetaBaseMixin):
         css = epub.EpubItem(uid="style_nav", file_name="style/epub.css", media_type="text/css", content=style.read())
         self.book.add_item(css)
 
+        if collection:
+            self.collections = [collection]
+            mode_single = True
+            instance = collection
+        else:
+            self.collections = self.corpus.children.all()
+            mode_single = False
+            instance = self.corpus
+
         # add cover image
-        for media in self.corpus.related.all():
+        for media in instance.related.all():
             if 'cover' in media.title or 'Cover' in media.title:
                 filename = os.path.split(media.file.path)[-1]
                 self.book.set_cover(filename, open(media.file.path, 'r').read())
@@ -84,16 +95,10 @@ class BaseEpubMixin(TelemetaBaseMixin):
         context = {}
         preamble = epub.EpubHtml(title='Preamble', file_name='preamble' + '.xhtml', lang='fr')
         preamble.content = render_to_string(self.template_preamble, context)
+        preamble.is_chapter = False
         self.book.add_item(preamble)
         self.chapters.append(preamble)
 
-        if collection:
-            self.collections = [collection]
-            mode_single = True
-        else:
-            self.collections = self.corpus.children.all()
-            mode_single = False
-
         for collection in self.collections:
             items = {}
             for item in collection.items.all():
@@ -113,11 +118,22 @@ class BaseEpubMixin(TelemetaBaseMixin):
                     filename = str(item.file)
                     epub_item = epub.EpubItem(file_name=str(item.file), content=audio.read())
                     self.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())
-                        self.book.add_item(epub_item)
+
+                related_all = item.related.all()
+                if related_all:
+                    for related in 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())
+                            self.book.add_item(epub_item)
+                elif not default_image_added:
+                    image = open(self.default_image, 'r')
+                    default_image_relative_path = 'images' + os.sep + os.path.split(self.default_image)[-1]
+                    epub_item = epub.EpubItem(file_name=default_image_relative_path,
+                                        content=image.read())
+                    self.book.add_item(epub_item)
+                    default_image_added = True
+
 
             title_split = collection.title.split(' - ')
             if len(title_split) > 1:
@@ -132,7 +148,7 @@ class BaseEpubMixin(TelemetaBaseMixin):
                 subtitle = ''
 
             context = {'collection': collection, 'title': title, 'subtitle': subtitle,
-                        'site': site, 'items': items}
+                        'site': site, 'items': items, 'default_image': default_image_relative_path}
             c = epub.EpubHtml(title=' - '.join([title, subtitle]), file_name=collection.code + '.xhtml', lang='fr')
             c.content = render_to_string(self.template, context)
             self.chapters.append(c)