1
0
Fork 0
satnogs-db/db/base/templatetags/tags.py

28 lines
722 B
Python
Raw Normal View History

2015-07-11 12:25:16 -06:00
from django import template
from django.core.urlresolvers import reverse
from django.utils.html import format_html
2015-07-11 12:25:16 -06:00
register = template.Library()
@register.simple_tag
def active(request, urls):
2015-07-17 11:59:23 -06:00
if request.path in (reverse(url) for url in urls.split()):
2015-07-11 12:25:16 -06:00
return 'active'
return None
@register.filter
def frq(value):
try:
to_format = float(value)
except (TypeError, ValueError):
return ''
2017-03-25 06:22:37 -06:00
prec = int(to_format % 1000)
formatted = format((to_format // 1000) / 1000, '.3f')
if prec:
stripped = str(prec).rstrip('0')
formatted = format_html('{0}<small>{1}</small>', formatted, stripped)
response = format_html('{0} MHz', formatted)
2017-03-25 06:22:37 -06:00
return response