]> git.parisson.com Git - telemeta.git/commitdiff
improve epub import / export
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 27 Apr 2015 11:08:02 +0000 (13:08 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 27 Apr 2015 15:06:06 +0000 (17:06 +0200)
telemeta/management/commands/telemeta-import-corpus-epub.py
telemeta/static/telemeta/css/telemeta_epub.css
telemeta/templates/telemeta/collection_epub.html
telemeta/views/resource.py

index a9f0556110b6b63e88089ba0df31ece09fb2e12b..539ac87eb5a58d6f6f4cf19ae3a2d1bc48310d42 100644 (file)
@@ -64,9 +64,15 @@ class Command(BaseCommand):
                 path = os.path.join(chapter_dir, filename)
                 if os.path.isfile(path) and '.txt' == os.path.splitext(filename)[1]:
                     f = open(path, 'r')
+                    i = 0
                     for line in f.readlines():
                         data = re.split(r'\t+', line.rstrip('\t'))
-                        metadata[data[0]] = data[1:]
+                        if i == 0:
+                            chapter_title = data[1]
+                            print chapter_title
+                        else:
+                            metadata[data[0]] = data[1:]
+                        i += 1
                     print metadata
                     break
 
@@ -99,7 +105,9 @@ class Command(BaseCommand):
 
                         corpus, c = MediaCorpus.objects.get_or_create(code=corpus_id, title=corpus_name)
 
-                        collection, c = MediaCollection.objects.get_or_create(code=collection_id, title=collection_name)
+                        collection_title = collection_name.replace('_', ' ') + ' : ' + chapter_title
+                        print collection_title
+                        collection, c = MediaCollection.objects.get_or_create(code=collection_id, title=collection_title)
                         if not collection in corpus.children.all():
                             corpus.children.add(collection)
 
@@ -110,9 +118,10 @@ class Command(BaseCommand):
                             item.file = media_path
                             item.save()
 
-                            title = data[1].split('.')
+                            title = data[0].split('.')
                             item.title = title[0]
-                            item.track = data[2].replace('\n', '')
+                            print data
+                            item.track = data[1].replace('\n', '')
                             if len(title) > 1:
                                  item.comment = '. '.join(title[1:])
                             item.save()
index 816fb29d1c51b1542e5a398a7e6b45ec2ca01c9c..c04973751adb87a315887b2795c6c2b3518faae5 100644 (file)
@@ -51,4 +51,5 @@ nav[epub|type~='toc'] > ol > li > ol > li {
 img {
     text-align: center;
     width: 50%;
+    height: auto;
 }
index e401f1db63aadb3e321c6ffea43bbb2ec99f4664..8863d7fa9ae523d92b2583a75e8b40367349829f 100644 (file)
@@ -1,9 +1,11 @@
 <link rel="stylesheet" type="text/css" href="style/nav.css" />
 
+<h2>{{ collection.title }}</h2>
+
 {% for item in items %}
 <div class="item">
   <h3>
-  <b>Son {{ item.old_code }}</b> : {{ item.title }}. {{ item.comment }} (fig. {{ item.track }}, p. )
+  <b>Son {{ item.old_code }}</b> : {{ item.title }}. {{ item.comment }} ({{ item.track }})
   </h3>
 
   <div class="item-audio">
index cdf39c10f7e8a57f43164f5de5718bf7ea6e55ca..73ea30d0a34b939b2cda41fea9975f9372ad54cd 100644 (file)
@@ -394,7 +394,11 @@ class CorpusEpubView(View):
         for collection in corpus.children.all():
             items = {}
             for item in collection.items.all():
-                id = item.old_code.split('.')[1].replace('a', '.1').replace('b', '.2')
+                if '.' in item.old_code:
+                    id = item.old_code.split('.')[1]
+                else:
+                    id = item.old_code
+                id = id.replace('a', '.1').replace('b', '.2')
                 items[item] = float(id)
             items = OrderedDict(sorted(items.items(), key=lambda t: t[1]))