addons-server/apps/reviews/helpers.py

34 строки
1.0 KiB
Python
Исходник Обычный вид История

2009-10-23 03:43:38 +04:00
import jinja2
2010-03-04 03:43:42 +03:00
import jingo
from tower import ugettext as _
2009-10-23 03:43:38 +04:00
2010-03-04 03:43:42 +03:00
@jingo.register.filter
2009-10-23 03:43:38 +04:00
def stars(num):
# check for 0.0 incase None was cast to a float. Should
# be safe since lowest rating you can give is 1.0
if num is None or num == 0.0:
2009-10-23 03:43:38 +04:00
return _('Not yet rated')
else:
num = min(5, int(round(num)))
rating = '<span itemprop="rating">%s</span>' % num
title = _('Rated %s out of 5 stars') % num
msg = _('Rated %s out of 5 stars') % rating
s = (u'<span class="stars stars-{num}" title="{title}">{msg}</span>'
.format(num=num, title=title, msg=msg))
2009-10-23 03:43:38 +04:00
return jinja2.Markup(s)
2010-02-12 21:07:48 +03:00
2010-03-04 03:43:42 +03:00
@jingo.register.filter
2010-02-12 21:07:48 +03:00
def reviews_link(addon, collection_uuid=None):
2010-03-04 03:43:42 +03:00
t = jingo.env.get_template('reviews/reviews_link.html')
return jinja2.Markup(t.render(addon=addon,
collection_uuid=collection_uuid))
@jingo.register.inclusion_tag('reviews/report_review.html')
@jinja2.contextfunction
def report_review_popup(context):
return context