Don't contruct button image URLs by hand, use Django static media handling code

This commit is contained in:
Roberto Rosario
2015-01-07 04:20:52 -04:00
parent 2f593c5a6f
commit b7f11b8e9d

View File

@@ -7,6 +7,7 @@ from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse
from django.template import RequestContext, Variable
from django.utils.safestring import mark_safe
from django.contrib.staticfiles.storage import staticfiles_storage
from django.utils.translation import ugettext_lazy as _
from permissions.models import Permission
@@ -39,10 +40,9 @@ def render_widget(request, link):
links = resolve_links(context, [link], current_view, current_path, parsed_query_string)
if links:
link = links[0]
return mark_safe(u'<a style="text-decoration:none; margin-right: 10px;" href="%(url)s"><button style="vertical-align: top; padding: 1px; width: 110px; height: 100px; margin: 10px;"><img src="%(static_url)smain/icons/%(icon)s" alt="%(image_alt)s" /><p style="margin: 0px 0px 0px 0px;">%(string)s</p></button></a>' % {
return mark_safe(u'<a style="text-decoration:none; margin-right: 10px;" href="%(url)s"><button style="vertical-align: top; padding: 1px; width: 110px; height: 100px; margin: 10px;"><img src="%(static_url)s" alt="%(image_alt)s" /><p style="margin: 0px 0px 0px 0px;">%(string)s</p></button></a>' % {
'url': reverse(link['view']) if 'view' in link else link['url'],
'icon': link.get('icon', 'link_button.png'),
'static_url': settings.STATIC_URL,
'static_url': staticfiles_storage.url('main/icons/{0}'.format(link.get('icon', 'link_button.png'))),
'string': link['text'],
'image_alt': _(u'Icon'),
})