Source

indie-community / gamedb / templatetags / ohrrpgce.py

from django import template
from django.utils.safestring import mark_safe
from gamedb.models import Game

register = template.Library()

@register.filter
def yesnoicon(value):
    icon = "ok" if value else "remove"
    return mark_safe('<i class="icon-%s"></i>' % icon)

@register.filter
def ratingicon(value):
    return mark_safe('<i class="icon-star"></i>' * value)

@register.filter
def link(value):
    try:
        return mark_safe('<a href="%s">%s</a>' % (value.get_absolute_url(), value))
    except:
        return value

@register.inclusion_tag('gamedb/fragments/latest_games.html')
def latest_games():
    game_list = Game.objects.all().order_by('-date_added')[:3]
    return {'game_list':game_list}