make media_manager a property of MediaEntry in mixin.py
In all cases where get_media_manager(_media_type_as_string) was called in our code base we ultimately passed in a "MediaEntry().media_type" to get the matching MEDIA_MANAGER. It so makes sense to make this a function of the MediaEntry rather than a global function in mediagoblin.media_types and passing around media_entry.media_type as arguments all the time. It saves a few import statements and arguments. I also made it so the Media_manager property is cached for subsequent calls, although I am not too sure that this is needed (there are other cases for which this would make more sense) Also add a get_media_manager test to the media submission tests. It submits an image and checks that both media.media_type and media.media_manager return the right thing. Not sure if these tests could not be merged with an existing submission test, but it can't hurt to have things explicit. TODO: Right now we iterate through all existing media_managers to find the right one based on the string of its module name. This should be made a simple dict lookup to avoid all the extra work. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
@@ -78,25 +78,6 @@ def get_media_managers():
|
||||
yield media_type, sys.modules[media_type].MEDIA_MANAGER
|
||||
|
||||
|
||||
def get_media_manager(_media_type):
|
||||
'''
|
||||
Get the MEDIA_MANAGER based on a media type string
|
||||
|
||||
Example::
|
||||
get_media_type('mediagoblin.media_types.image')
|
||||
'''
|
||||
if not _media_type:
|
||||
return False
|
||||
|
||||
for media_type, manager in get_media_managers():
|
||||
if media_type in _media_type:
|
||||
return manager
|
||||
|
||||
# Nope? Then raise an error
|
||||
raise FileTypeNotSupported(
|
||||
"MediaManager not in enabled types. Check media_types in config?")
|
||||
|
||||
|
||||
def get_media_type_and_manager(filename):
|
||||
'''
|
||||
Try to find the media type based on the file name, extension
|
||||
|
||||
Reference in New Issue
Block a user