add option media creation date in createmediacontent V01.65.01
authorymh <ymh.work@gmail.com>
Wed, 22 Apr 2020 17:19:13 +0200
changeset 1497 c42847c334a0
parent 1496 9089943b572a
child 1498 4a621313cf3c
add option media creation date in createmediacontent
src/ldt/ldt/__init__.py
src/ldt/ldt/management/commands/createmediacontent.py
--- a/src/ldt/ldt/__init__.py	Mon Oct 22 17:44:26 2018 +0200
+++ b/src/ldt/ldt/__init__.py	Wed Apr 22 17:19:13 2020 +0200
@@ -1,6 +1,6 @@
 __all__ = ["VERSION", "get_version", "__version__", "default_app_config"]
 
-VERSION = (1, 65, 0, "final", 0)
+VERSION = (1, 65, 1, "final", 0)
 
 
 def get_version():
--- a/src/ldt/ldt/management/commands/createmediacontent.py	Mon Oct 22 17:44:26 2018 +0200
+++ b/src/ldt/ldt/management/commands/createmediacontent.py	Wed Apr 22 17:19:13 2020 +0200
@@ -5,6 +5,7 @@
 @author: ymh
 '''
 
+import dateutil.parser
 import logging
 from optparse import make_option
 import time
@@ -27,9 +28,9 @@
 
 
 class Command(BaseCommand):
-    
+
     formats = ["%M:%S", "%H:%M:%S", "%Hh%M", "%Ss", "%Ssec", "%Mmn %Ss"]
-    
+
     def get_duration(self, value):
         dur = None
         for f in self.formats:
@@ -41,7 +42,7 @@
                 pass
         return dur
 
-    
+
     help = 'Create a content (and Media)'
     option_list = BaseCommand.option_list + (
 
@@ -90,7 +91,7 @@
                   action="store",
                   type="string",
                   help="Media duration"),
-        
+
         make_option("-p", "--public",
                     dest="public",
                     action="store_true",
@@ -142,12 +143,22 @@
                     default = None,
                     help="The media external id"
                     ),
+
+        make_option("-C", "--creation-date",
+                    dest='creation_date',
+                    action="store",
+                    type="string",
+                    default = None,
+                    help="The creation date in ISO 8601 format (2008-09-03T20:56:35.450686)"
+                    ),
+
+
        )
-        
-    
+
+
     def handle(self, *args, **options):
         #BaseCommand.handle(self, *args, **options)
-        
+
         title = options.get('title', '')
         if not title:
             raise CommandError("Title s compulsory")
@@ -159,7 +170,7 @@
         src = options.get('source', None)
         if src:
             src = src.decode("utf-8")
-        
+
         if not src:
             raise CommandError("Source option is compulsory")
         videopath = options.get('videopath', settings.STREAM_URL)
@@ -171,18 +182,18 @@
         duration = self.get_duration(duration_str)
         if duration is None:
             raise CommandError("Duration %r not recognized" % duration_str)
-        
+
         description = options.get('description', '')
         if description:
             description  = description.decode("utf-8")
 
         media_description = options.get('media_description', '')
-        
+
         if not media_description:
             media_description = description
         else:
             media_description.decode("utf-8")
-        
+
         public = options.get('public', False)
 
         tags_str = options.get('tags', '')
@@ -207,33 +218,37 @@
                 creator = User.objects.filter(is_superuser=True)[0]
             except IndexError:
                 creator = None
-        
+
         if creator is None:
             raise CommandError("Creator not found")
 
         readers_str = options.get("readers", "")
         writers_str = options.get("writers", "")
-        
+
         readers = filter(lambda s: s, [r.strip() for r in  readers_str.split(',')]) if readers_str else []
         writers = filter(lambda s: s, [r.strip() for r in  writers_str.split(',')]) if writers_str else []
-        
+
         readers_list = set(readers+writers)
-        
-        
+
+
         if readers_list:
             read_list = list(User.objects.filter(username__in=readers_list)) + list(Group.objects.filter(name__in=readers_list))
         else:
             read_list = []
-        
+
         if writers:
             write_list = list(User.objects.filter(username__in = writers)) + list(Group.objects.filter(name__in = writers))
         else:
             write_list = []
 
         external_id = options.get("external_id", None)
-        
+
         update_objects = options.get('update', False)
-        
+
+        creation_date_str = options.get('creation_date', None)
+
+        creation_date = dateutil.parser.parse(creation_date_str) if creation_date_str else None
+
         #TODO: wrap everything in transaction
         defaults_values = {
             'videopath': videopath,
@@ -241,11 +256,12 @@
             'duration': duration,
             'description': media_description,
             'creator': creator,
-            'external_id': external_id
+            'external_id': external_id,
+            'media_creation_date': creation_date
         }
 
         media, created = Media.objects.get_or_create(src=src, defaults= defaults_values)
-        
+
         if not created and update_objects:
             for k,v in defaults_values.items():
                 setattr(media, k, v)
@@ -262,12 +278,12 @@
             iriurl = content_iriurl,
             media_obj=media,
             title=title,
-            description=description, 
+            description=description,
             duration=duration
         )
-        
+
         content.tags.add(*tags)
-        
+
         everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
         if public:
             cached_assign('view_content', everyone, content)
@@ -280,8 +296,8 @@
 
         content.is_public = public
         content.save()
-        
+
         assign_perm_to_obj(content, read_list, write_list, creator)
         update_stat_content(content)
-        
+
         return content.iri_id