Video media_data: Change layout in the mongo world
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Thu, 1 Mar 2012 20:59:26 +0000 (21:59 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Thu, 1 Mar 2012 21:25:41 +0000 (22:25 +0100)
Change the media_data for video from
entry.media_data["video"] to use entry.media_data directly.

Also start a bare MediaEntry.media_data_init(**kwargs)
method for setting up the media_data and possibly
initialising it with kwargs.

mediagoblin/db/mongo/migrations.py
mediagoblin/db/mongo/models.py
mediagoblin/media_types/video/processing.py
mediagoblin/templates/mediagoblin/media_displays/video.html

index 59035f3b44496bff2125c08031e13f06615fcb12..c5766b0d8687e4d25ff114e692c01809d233d8d8 100644 (file)
@@ -139,3 +139,17 @@ def remove_calculated_html(database):
     drop_table_field(database, 'users', 'bio_html')
     drop_table_field(database, 'media_entries', 'description_html')
     drop_table_field(database, 'media_comments', 'content_html')
+
+@RegisterMigration(10)
+def convert_video_media_data(database):
+    """
+    Move media_data["video"] directly into media_data
+    """
+    collection = database['media_entries']
+    target = collection.find(
+        {'media_data.video': {'$exists': True}})
+
+    for document in target:
+        assert len(document['media_data']) == 1
+        document['media_data'] = document['media_data']['video']
+        collection.save(document)
index 99c7905d80fca9146f24206fd760433671eecb17..c86adbb6f60d7a09c1906305d46adccd381cfc5e 100644 (file)
@@ -220,6 +220,9 @@ class MediaEntry(Document, MediaEntryMixin):
 
     id = MongoPK()
 
+    def media_data_init(self, **kwargs):
+        self.media_data.update(kwargs)
+
     def get_comments(self, ascending=False):
         if ascending:
             order = ASCENDING
index 9dc23c55bb495ef54ab7af7d3858fce27fb5303e..3a47980259c129ed23f697f5cd21a2ee8ca5cd95 100644 (file)
@@ -77,9 +77,9 @@ def process_video(entry):
         entry.media_files['webm_640'] = medium_filepath
 
         # Save the width and height of the transcoded video
-        entry.media_data['video'] = {
-            u'width': transcoder.dst_data.videowidth,
-            u'height': transcoder.dst_data.videoheight}
+        entry.media_data_init(
+            width=transcoder.dst_data.videowidth,
+            height=transcoder.dst_data.videoheight)
 
     # Create a temporary file for the video thumbnail
     tmp_thumb = tempfile.NamedTemporaryFile()
index ec4338fa3147e44f36868690a32d5129055bb6fc..acd570e758324278fcfe62a8bb673eb5e98690c9 100644 (file)
@@ -21,8 +21,8 @@
 {% block mediagoblin_media %}
   <div class="video-player" style="position: relative;">
     <video class="video-js vjs-default-skin"
-          width="{{ media.media_data.video.width }}"
-          height="{{ media.media_data.video.height }}"
+          width="{{ media.media_data.width }}"
+          height="{{ media.media_data.height }}"
           controls="controls"
           preload="auto"
           data-setup="">