Source

HackersEdge / he_one / templatetags / hackers_edge.py

Full commit
Kevin Veroneau 8d6c3a4 
































from django import template
from django.utils.safestring import mark_safe
from django.utils.html import escape
from he_one.models import UserPermission, FilePermission

register = template.Library()

@register.filter
def yesnoicon(value):
    icon = "check" if value else "cancel"
    return mark_safe('<span class="ui-icon ui-icon-%s" style="float:left;"></span>' % icon)

@register.filter
def ratingicon(value):
    return mark_safe('<span class="ui-icon ui-icon-star" style="float:left;"></span>' * value)

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

@register.simple_tag
def showicon(icon):
    return mark_safe('<span class="ui-icon ui-icon-%s" style="float:left;"></span>' % icon)

@register.assignment_tag
def get_user_permissions(host):
    return UserPermission.objects.filter(host=host)

@register.assignment_tag
def get_file_permissions(host):
    return FilePermission.objects.filter(host=host, is_hidden=False, deleted=False)