Turning image's media manager into a new style class.
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 13 Mar 2013 21:38:28 +0000 (22:38 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 17 Apr 2013 10:09:30 +0000 (12:09 +0200)
images are the first media type to use the new style class
based media manager.

mediagoblin/media_types/image/__init__.py
mediagoblin/tests/test_submission.py

index 3e167db1f74b7bd7d19a82c21d3a6c04ad4c19c3..15cc8ddab8d10134a392badf0f7728cb76e0b0f2 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from mediagoblin.media_types import MediaManagerBase
 from mediagoblin.media_types.image.processing import process_image, \
     sniff_handler
 
 
-MEDIA_MANAGER = {
-    "human_readable": "Image",
-    "processor": process_image, # alternately a string,
-                                # 'mediagoblin.media_types.image.processing'?
-    "sniff_handler": sniff_handler,
-    "display_template": "mediagoblin/media_displays/image.html",
-    "default_thumb": "images/media_thumbs/image.png",
-    "accepted_extensions": ["jpg", "jpeg", "png", "gif", "tiff"],
+class ImageMediaManager(MediaManagerBase):
+    human_readable = "Image"
+    processor = staticmethod(process_image)
+    sniff_handler = staticmethod(sniff_handler)
+    display_template = "mediagoblin/media_displays/image.html"
+    default_thumb = "images/media_thumbs/image.png"
+    accepted_extensions = ["jpg", "jpeg", "png", "gif", "tiff"]
+    media_fetch_order = [u'medium', u'original', u'thumb']
+    
 
-    # Used by the media_entry.get_display_media method
-    "media_fetch_order": [u'medium', u'original', u'thumb'],
-}
+MEDIA_MANAGER = ImageMediaManager
index 0d74848aad4512b8c11caa1570e155bd9423f03f..1430d062be8c81622430459f6ce9d14b1f542729 100644 (file)
@@ -231,7 +231,7 @@ class TestSubmission:
         media = self.check_media(request, {'title': u'Balanced Goblin'}, 1)
 
         assert media.media_type == u'mediagoblin.media_types.image'
-        assert media.media_manager.mm_dict == img_MEDIA_MANAGER
+        assert isinstance(media.media_manager, img_MEDIA_MANAGER)
         assert media.media_manager.entry == media