Use mediagoblin import machinery

Rather than manually __importing__ the MEDIA_MANAGER, we should have
been using tools.common.import_component in the first place.

But even better to use the existing get_media_manager() function that
exists for exactly our purpose. Also improve documentation of what happens
in case of failure.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2012-11-30 14:25:26 +01:00
parent 27886480ab
commit df1c497609

View File

@ -29,6 +29,7 @@ real objects.
from mediagoblin import mg_globals
from mediagoblin.auth import lib as auth_lib
from mediagoblin.media_types import get_media_manager
from mediagoblin.tools import common, licenses
from mediagoblin.tools.text import cleaned_markdown_conversion
from mediagoblin.tools.url import slugify
@ -122,11 +123,11 @@ class MediaEntryMixin(object):
thumb_url = mg_globals.app.public_store.file_url(
self.media_files[u'thumb'])
else:
# no thumbnail in media available. Get the media's
# No thumbnail in media available. Get the media's
# MEDIA_MANAGER for the fallback icon and return static URL
manager = __import__(self.media_type)
thumb_url = manager.MEDIA_MANAGER[u'default_thumb']
thumb_url = mg_globals.app.staticdirector(thumb_url) # use static
# Raise FileTypeNotSupported in case no such manager is enabled
manager = get_media_manager(self.media_type)
thumb_url = mg_globals.app.staticdirector(manager[u'default_thumb'])
return thumb_url
def get_fail_exception(self):