bornhack-website/shop/templatetags/shop_tags.py

23 lines
525 B
Python
Raw Normal View History

from django import template
2016-05-29 13:21:55 +00:00
from django.utils.safestring import mark_safe
2016-05-31 04:51:30 +00:00
from decimal import Decimal
register = template.Library()
@register.filter
def currency(value):
2016-05-30 16:18:31 +00:00
try:
2016-05-31 04:51:30 +00:00
return "{0:.2f} DKK".format(Decimal(value))
2016-05-30 16:18:31 +00:00
except ValueError:
return False
2016-05-29 13:21:55 +00:00
@register.filter()
2016-05-29 13:16:29 +00:00
def truefalseicon(value):
if value:
2016-05-29 13:35:14 +00:00
return mark_safe("<span class='text-success glyphicon glyphicon-ok'></span>")
2016-05-29 13:16:29 +00:00
else:
2016-05-29 13:35:14 +00:00
return mark_safe("<span class='text-danger glyphicon glyphicon-remove'></span>")
2016-05-29 13:16:29 +00:00