Last Updated: February 25, 2016
·
813
· ubersoldat

Jinja2 Stars Filter for Bootstrap

@app.template_filter('stars')
def _jinja2_filter_stars(value):
    """
    Adds filled and empty stars 
    Usage: {{ obj.stars|stars|safe }}
    """
    ret = ""
    if value:
        for i in range(1, value+1):
            ret += '<i class="icon-star"></i>'

        for i in range(value, 5):
            ret += '<i class="icon-star-empty"></i>'
    return ret