addons-server/apps/reviews/helpers.py

20 строки
441 B
Python
Исходник Обычный вид История

2009-10-23 03:43:38 +04:00
import math
from django.utils.translation import ugettext as _
import jinja2
from jingo import register
@register.filter
def stars(num):
if num is None:
return _('Not yet rated')
else:
2009-12-17 23:00:04 +03:00
stars = int(math.ceil(num))
2009-10-23 03:43:38 +04:00
msg = _('Rated %s out of 5 stars') % stars
s = ('<span class="stars stars-{num}" title="{msg}">{msg}</span>'
2009-12-17 23:00:04 +03:00
.format(num=stars, msg=msg))
2009-10-23 03:43:38 +04:00
return jinja2.Markup(s)