# HG changeset patch # User Thierry Florac # Date 1505130263 -7200 # Node ID 55d5fde71e8ffc5dcb37b415e784f8af64fd7bf6 # Parent bf32240cb696bfbfa306d34b07eed5d230a9efef Added check on content type when adding conversion diff -r bf32240cb696 -r 55d5fde71e8f src/pyams_media/media.py --- a/src/pyams_media/media.py Mon Sep 11 13:43:22 2017 +0200 +++ b/src/pyams_media/media.py Mon Sep 11 13:44:23 2017 +0200 @@ -84,10 +84,15 @@ alsoProvides(target, IMediaConversion) if extension is None: extension = guess_extension(format) - target_name = '{name}{width}.{extension}'.format(name=target.content_type.decode().split('/', 1)[0] - if target.content_type else 'media', + content_type = target.content_type + if isinstance(content_type, bytes): + content_type = content_type.decode() + target_name = '{name}{width}.{extension}'.format(name=content_type.split('/', 1)[0] + if content_type else 'media', width='-{0}'.format(width) if width else '', extension=extension) + if target_name in self: + del self[target_name] target.filename = target_name self[target_name] = target return target diff -r bf32240cb696 -r 55d5fde71e8f src/pyams_media/video.py --- a/src/pyams_media/video.py Mon Sep 11 13:43:22 2017 +0200 +++ b/src/pyams_media/video.py Mon Sep 11 13:44:23 2017 +0200 @@ -191,7 +191,7 @@ @property def video_type(self): - return b'video/flash' + return 'video/flash' @adapter_config(name='video_type', context=(IVideo, Interface, Interface), provides=ITALESExtension) @@ -202,8 +202,14 @@ if context is None: context = self.context registry = self.request.registry - adapter = registry.queryAdapter(context, IVideoType, name=context.content_type.decode()) + content_type = context.content_type + if isinstance(content_type, bytes): + content_type = content_type.decode() + adapter = registry.queryAdapter(context, IVideoType, name=content_type) if adapter is None: adapter = registry.queryAdapter(context, IVideoType) if adapter is not None: - return adapter.video_type.decode() + video_type = adapter.video_type + if isinstance(video_type, bytes): + video_type = video_type.decode() + return video_type