Commit 255862a6 authored by Michal Čihař's avatar Michal Čihař

Allow widgets to specify content type and extension

Issue #467
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 9752303b
......@@ -74,6 +74,7 @@ def widgets(request, project):
'project': obj.slug,
'widget': widget_name,
'color': color,
'extension': widget_class.extension,
}
)
else:
......@@ -83,7 +84,8 @@ def widgets(request, project):
'project': obj.slug,
'widget': widget_name,
'color': color,
'lang': lang.code
'lang': lang.code,
'extension': widget_class.extension,
}
)
color_list.append({
......@@ -111,7 +113,7 @@ def widgets(request, project):
@cache_page(3600)
def render_widget(request, project, widget='287x66', color=None, lang=None):
def render_widget(request, project, widget='287x66', color=None, lang=None, extension='png'):
obj = get_project(request, project)
# Handle language parameter
......@@ -137,4 +139,7 @@ def render_widget(request, project, widget='287x66', color=None, lang=None):
# Get image data
data = widget.get_image()
return HttpResponse(content_type='image/png', content=data)
return HttpResponse(
content_type=widget.content_type,
content=data
)
......@@ -69,6 +69,8 @@ class Widget(object):
colors = ('grey', 'white', 'black')
progress = None
alpha = False
extension = 'png'
content_type = 'image/png'
def __init__(self, obj, color=None, lang=None):
'''
......@@ -332,6 +334,8 @@ register_widget(BadgeWidget)
class ShieldsBadgeWidget(Widget):
name = 'shields'
colors = ('badge', )
extension = 'svg'
content_type = 'image/svg+xml'
def redirect(self):
if ENABLE_HTTPS:
......
......@@ -49,6 +49,9 @@ PROJECT_LANG = PROJECT + LANGUAGE + '/'
# URL regexp used as base for widgets
WIDGET = r'(?P<project>[^/]+)-(?P<widget>[^/-]+)-(?P<color>[^/-]+)'
# Widget extension match
EXTENSION = r'(?P<extension>(png|svg))'
admin.autodiscover()
handler403 = 'weblate.trans.views.basic.denied'
......@@ -492,12 +495,12 @@ urlpatterns = patterns(
# Engagement widgets
url(
r'^widgets/' + WIDGET + '-' + LANGUAGE + r'\.png$',
r'^widgets/' + WIDGET + '-' + LANGUAGE + r'\.' + EXTENSION + r'$',
'weblate.trans.views.widgets.render_widget',
name='widget-image-lang',
),
url(
r'^widgets/' + WIDGET + r'\.png$',
r'^widgets/' + WIDGET + r'\.' + EXTENSION + r'$',
'weblate.trans.views.widgets.render_widget',
name='widget-image',
),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment