From: Guillaume Pellerin Date: Fri, 22 May 2015 16:18:47 +0000 (+0200) Subject: fix variable X-Git-Tag: 1.6a~4^2~56 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=9a625f7b5dab763d707bed8a0fbfa5fd922d0357;p=telemeta.git fix variable --- diff --git a/telemeta/management/commands/telemeta-import-corpus-from-dir.py b/telemeta/management/commands/telemeta-import-corpus-from-dir.py index d86c22e0..30a84bf3 100644 --- a/telemeta/management/commands/telemeta-import-corpus-from-dir.py +++ b/telemeta/management/commands/telemeta-import-corpus-from-dir.py @@ -98,20 +98,6 @@ class Command(BaseCommand): for chapter in chapters: chapter_dir = os.path.join(self.source_dir, chapter) metadata = {} - collection_name = chapter - collection_id = corpus_id + '_' + slugify(unicode(collection_name)) - collection_title = collection_name.replace('_', ' ') + ' - ' + chapter_title - print collection_title - cc = MediaCollection.objects.filter(code=collection_id, title=collection_title) - if cc: - collection = cc[0] - else: - collection = MediaCollection(code=collection_id) - collection.title = collection_title - collection.save() - - if not collection in corpus.children.all(): - corpus.children.add(collection) for filename in os.listdir(chapter_dir): path = os.path.join(chapter_dir, filename) @@ -127,12 +113,26 @@ class Command(BaseCommand): metadata[data[0]] = data[1:] i += 1 print metadata + collection_name = chapter + collection_id = corpus_id + '_' + slugify(unicode(collection_name)) + collection_title = collection_name.replace('_', ' ') + ' - ' + chapter_title + print collection_title + cc = MediaCollection.objects.filter(code=collection_id, title=collection_title) + if cc: + collection = cc[0] + else: + collection = MediaCollection(code=collection_id) + collection.title = collection_title + collection.save() + if not collection in corpus.children.all(): + corpus.children.add(collection) if os.path.isfile(path) and '.jpg' == os.path.splitext(filename)[1]: related_path = path.replace(self.media_root, '') related, c = MediaCollectionRelated.objects.get_or_create(collection=collection, file=related_path) + for root, dirs, files in os.walk(chapter_dir): for media_file in files: path = os.path.join(root, media_file) @@ -171,7 +171,6 @@ class Command(BaseCommand): related_path = os.sep.join(root_list[-4:]) + os.sep + related_file related_name = os.path.splitext(related_file)[0] related_ext = os.path.splitext(related_file)[1][1:] - if related_ext in self.image_formats: related, c = MediaItemRelated.objects.get_or_create(item=item, file=related_path) if len(data) > 2: