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>
This commit is contained in:
parent
ee62c51d79
commit
2e4ad35962
@ -27,6 +27,8 @@ These functions now live here and get "mixed in" into the
|
|||||||
real objects.
|
real objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import importlib
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.auth import lib as auth_lib
|
from mediagoblin.auth import lib as auth_lib
|
||||||
from mediagoblin.tools import common, licenses
|
from mediagoblin.tools import common, licenses
|
||||||
@ -112,6 +114,23 @@ class MediaEntryMixin(object):
|
|||||||
media=self.slug_or_id,
|
media=self.slug_or_id,
|
||||||
**extra_args)
|
**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):
|
def get_fail_exception(self):
|
||||||
"""
|
"""
|
||||||
Get the exception that's appropriate for this error
|
Get the exception that's appropriate for this error
|
||||||
|
@ -24,5 +24,5 @@ MEDIA_MANAGER = {
|
|||||||
# 'mediagoblin.media_types.image.processing'?
|
# 'mediagoblin.media_types.image.processing'?
|
||||||
"sniff_handler": sniff_handler,
|
"sniff_handler": sniff_handler,
|
||||||
"display_template": "mediagoblin/media_displays/image.html",
|
"display_template": "mediagoblin/media_displays/image.html",
|
||||||
"default_thumb": "images/media_thumbs/image.jpg",
|
"default_thumb": "images/media_thumbs/image.png",
|
||||||
"accepted_extensions": ["jpg", "jpeg", "png", "gif", "tiff"]}
|
"accepted_extensions": ["jpg", "jpeg", "png", "gif", "tiff"]}
|
||||||
|
BIN
mediagoblin/static/images/media_thumbs/image.png
Normal file
BIN
mediagoblin/static/images/media_thumbs/image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
@ -36,8 +36,7 @@
|
|||||||
Editing attachments for {{ media_title }}
|
Editing attachments for {{ media_title }}
|
||||||
{%- endtrans %}</h1>
|
{%- endtrans %}</h1>
|
||||||
<div style="text-align: center;" >
|
<div style="text-align: center;" >
|
||||||
<img src="{{ request.app.public_store.file_url(
|
<img src="{{ media.thumb_url }}" />
|
||||||
media.media_files['thumb']) }}" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if media.attachment_files|count %}
|
{% if media.attachment_files|count %}
|
||||||
|
@ -34,8 +34,7 @@
|
|||||||
<div class="form_box_xl edit_box">
|
<div class="form_box_xl edit_box">
|
||||||
<h1>{% trans media_title=media.title %}Editing {{ media_title }}{% endtrans %}</h1>
|
<h1>{% trans media_title=media.title %}Editing {{ media_title }}{% endtrans %}</h1>
|
||||||
<div style="text-align: center;" >
|
<div style="text-align: center;" >
|
||||||
<img src="{{ request.app.public_store.file_url(
|
<img src="{{ media.thumb_url }}" />
|
||||||
media.media_files['thumb']) }}" />
|
|
||||||
</div>
|
</div>
|
||||||
{{ wtforms_util.render_divs(form) }}
|
{{ wtforms_util.render_divs(form) }}
|
||||||
<div class="form_submit_buttons">
|
<div class="form_submit_buttons">
|
||||||
|
@ -35,8 +35,7 @@
|
|||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<div style="text-align: center;" >
|
<div style="text-align: center;" >
|
||||||
<img src="{{ request.app.public_store.file_url(
|
<img src="{{ collection_item.get_media_entry.thumb_url }}" />
|
||||||
collection_item.get_media_entry.media_files['thumb']) }}" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
@ -38,8 +38,7 @@
|
|||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<div style="text-align: center;" >
|
<div style="text-align: center;" >
|
||||||
<img src="{{ request.app.public_store.file_url(
|
<img src="{{ media.thumb_url }}" />
|
||||||
media.media_files['thumb']) }}" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
@ -33,8 +33,7 @@
|
|||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<div style="text-align: center;" >
|
<div style="text-align: center;" >
|
||||||
<img src="{{ request.app.public_store.file_url(
|
<img src="{{ media.thumb_url }}" />
|
||||||
media.media_files['thumb']) }}" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
@ -31,8 +31,7 @@
|
|||||||
{%- if loop.first %} thumb_entry_first
|
{%- if loop.first %} thumb_entry_first
|
||||||
{%- elif loop.last %} thumb_entry_last{% endif %}">
|
{%- elif loop.last %} thumb_entry_last{% endif %}">
|
||||||
<a href="{{ entry_url }}">
|
<a href="{{ entry_url }}">
|
||||||
<img src="{{ request.app.public_store.file_url(
|
<img src="{{ media_entry.thumb_url }}" />
|
||||||
media_entry.media_files['thumb']) }}" />
|
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
{% if item.note %}
|
{% if item.note %}
|
||||||
|
@ -30,8 +30,7 @@
|
|||||||
{%- if loop.first %} thumb_entry_first
|
{%- if loop.first %} thumb_entry_first
|
||||||
{%- elif loop.last %} thumb_entry_last{% endif %}">
|
{%- elif loop.last %} thumb_entry_last{% endif %}">
|
||||||
<a href="{{ entry_url }}">
|
<a href="{{ entry_url }}">
|
||||||
<img src="{{ request.app.public_store.file_url(
|
<img src="{{ entry.thumb_url }}" />
|
||||||
entry.media_files['thumb']) }}" />
|
|
||||||
</a>
|
</a>
|
||||||
{% if entry.title %}
|
{% if entry.title %}
|
||||||
<a class="thumb_entry_title" href="{{ entry_url }}">{{ entry.title }}</a>
|
<a class="thumb_entry_title" href="{{ entry_url }}">{{ entry.title }}</a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user