]> git.parisson.com Git - teleforma.git/commitdiff
fix double item
authorGuillaume Pellerin <yomguy@parisson.com>
Fri, 2 May 2014 12:27:43 +0000 (14:27 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Fri, 2 May 2014 12:27:43 +0000 (14:27 +0200)
teleforma/management/commands/teleforma-import-seminar-media.py

index 6d4b71e386c95ba14ac09ec2043177b49b748823..77dbe6f6b32afac3f6ab393e08d22c2c71bc325c 100644 (file)
@@ -86,6 +86,15 @@ class Command(BaseCommand):
         t[2] = t[2].split('.')[0]
         return ':'.join(t)
 
+    def get_item(self, collection, id):
+        items = MediaItem.objects.filter(collection=collection, code=id)
+            if not items:
+                item = MediaItem(collection=collection, code=id)
+                item.save()
+            else:
+                item = items[0]
+        return item
+
     def handle(self, *args, **options):
         organization_name = args[0]
         period_name = args[1]
@@ -145,6 +154,7 @@ class Command(BaseCommand):
                                             rank=seminar_rank, period=period)
                     if c:
                         seminar.title = course.title
+                        seminar.status = 1
                         seminar.save()
 
                     exist = False
@@ -169,13 +179,7 @@ class Command(BaseCommand):
 
                         id = '_'.join([period.name, '20', collection_id, ext, str(media_rank)])
 
-                        items = MediaItem.objects.filter(collection=collection, code=id)
-                        if not items:
-                            item = MediaItem(collection=collection, code=id)
-                            item.save()
-                        else:
-                            item = items[0]
-
+                        item = get_item(collection, id)
                         item.title = name
                         item.file = path
 
@@ -192,7 +196,7 @@ class Command(BaseCommand):
                                 related, c = MediaItemRelated.objects.get_or_create(item=item, file=r_path)
                                 related.title = 'preview'
                                 related.set_mime_type()
-                                related.save()
+                                related.save()  
                                 logger.logger.info(r_path)
                             elif extension[1:] in self.transcoded_formats:
                                 t, c = MediaItemTranscoded.objects.get_or_create(item=item, file=r_path)
@@ -204,7 +208,7 @@ class Command(BaseCommand):
                                     for marker in markers:
                                         if float(marker['time']) != 0:
                                             item.title = marker['comment']
-                                            item.save()
+                                            item.save() 
                                             break
                                 logger.logger.info(r_path)
 
@@ -226,7 +230,8 @@ class Command(BaseCommand):
                                 files = os.listdir(dir)
                                 code = item.code + '_preview'
                                 title = item.title + ' (preview)'
-                                item = MediaItem(collection=collection, code=code, title=title)
+                                item = get_item(collection, id)
+                                item.title = title
                                 item.save()
                                 for file in files:
                                     r_path = r_dir + os.sep + file