From: Guillaume Pellerin Date: Mon, 27 Apr 2015 11:08:02 +0000 (+0200) Subject: improve epub import / export X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=4ce873519770d3be69eb321c9b575f984e82ebc4;p=telemeta.git improve epub import / export --- diff --git a/telemeta/management/commands/telemeta-import-corpus-epub.py b/telemeta/management/commands/telemeta-import-corpus-epub.py index a9f05561..539ac87e 100644 --- a/telemeta/management/commands/telemeta-import-corpus-epub.py +++ b/telemeta/management/commands/telemeta-import-corpus-epub.py @@ -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() diff --git a/telemeta/static/telemeta/css/telemeta_epub.css b/telemeta/static/telemeta/css/telemeta_epub.css index 816fb29d..c0497375 100644 --- a/telemeta/static/telemeta/css/telemeta_epub.css +++ b/telemeta/static/telemeta/css/telemeta_epub.css @@ -51,4 +51,5 @@ nav[epub|type~='toc'] > ol > li > ol > li { img { text-align: center; width: 50%; + height: auto; } diff --git a/telemeta/templates/telemeta/collection_epub.html b/telemeta/templates/telemeta/collection_epub.html index e401f1db..8863d7fa 100644 --- a/telemeta/templates/telemeta/collection_epub.html +++ b/telemeta/templates/telemeta/collection_epub.html @@ -1,9 +1,11 @@ +

{{ collection.title }}

+ {% for item in items %}

- Son {{ item.old_code }} : {{ item.title }}. {{ item.comment }} (fig. {{ item.track }}, p. ) + Son {{ item.old_code }} : {{ item.title }}. {{ item.comment }} ({{ item.track }})

diff --git a/telemeta/views/resource.py b/telemeta/views/resource.py index cdf39c10..73ea30d0 100644 --- a/telemeta/views/resource.py +++ b/telemeta/views/resource.py @@ -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]))