aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/mixin.py
diff options
context:
space:
mode:
authorSebastian Spaeth <Sebastian@SSpaeth.de>2012-11-09 10:13:04 +0100
committerSebastian Spaeth <Sebastian@SSpaeth.de>2012-11-15 12:01:31 +0100
commit2e4ad359623916f5ca9f6ec11f5353a1a85a77d2 (patch)
tree30458eceed7b36f938566d317210fcd7b85bca75 /mediagoblin/db/mixin.py
parentee62c51d797ab317366fa099f5e012f33f42857f (diff)
downloadmediagoblin-2e4ad359623916f5ca9f6ec11f5353a1a85a77d2.tar.lz
mediagoblin-2e4ad359623916f5ca9f6ec11f5353a1a85a77d2.tar.xz
mediagoblin-2e4ad359623916f5ca9f6ec11f5353a1a85a77d2.zip
Simplify/Robustify the thumbnail URL usage in templates
So far templates required a very complex blurb to simply insert a thumbnail URL, exposing much of the internal logic to the template designer. In addition, we would fail with an error if for some reason the media_files['thumb'] entry was never populated. This adds the MediaEntry.thumb_url property that template designers can simply use. It will do the right thing, either fetching the proper thumbnail or hand back a generic icon specified in a media's MEDIA_MANAGER as "default_thumb". Add an image default fallback icon (stolen from Tangos, which are Public Domain since version 0.8.90 as I understand) since the one we referred to was not existing. Perhaps, a "broken image" icon would be better, but I'll leave that to our capable designers. All templates have been modified to make use of the new thumb_url function. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'mediagoblin/db/mixin.py')
-rw-r--r--mediagoblin/db/mixin.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py
index f6a15a12..22375b7f 100644
--- a/mediagoblin/db/mixin.py
+++ b/mediagoblin/db/mixin.py
@@ -27,6 +27,8 @@ These functions now live here and get "mixed in" into the
real objects.
"""
+import importlib
+
from mediagoblin import mg_globals
from mediagoblin.auth import lib as auth_lib
from mediagoblin.tools import common, licenses
@@ -112,6 +114,23 @@ class MediaEntryMixin(object):
media=self.slug_or_id,
**extra_args)
+ @property
+ def thumb_url(self):
+ """Return the thumbnail URL (for usage in templates)
+ Will return either the real thumbnail or a default fallback icon."""
+ # TODO: implement generic fallback in case MEDIA_MANAGER does
+ # not specify one?
+ if u'thumb' in self.media_files:
+ thumb_url = mg_globals.app.public_store.file_url(
+ self.media_files[u'thumb'])
+ else:
+ # no thumbnail in media available. Get the media's
+ # MEDIA_MANAGER for the fallback icon and return static URL
+ manager = importlib.import_module(self.media_type)
+ thumb_url = manager.MEDIA_MANAGER[u'default_thumb']
+ thumb_url = mg_globals.app.staticdirector(thumb_url) # use static
+ return thumb_url
+
def get_fail_exception(self):
"""
Get the exception that's appropriate for this error