2015-07-11 12:25:16 -06:00
|
|
|
from django import template
|
|
|
|
from django.core.urlresolvers import reverse
|
2016-11-10 10:14:51 -07:00
|
|
|
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
|
|
|
|
|
2015-07-11 12:25:40 -06:00
|
|
|
|
|
|
|
@register.filter
|
|
|
|
def frq(value):
|
|
|
|
try:
|
|
|
|
to_format = float(value)
|
2015-09-17 05:33:28 -06:00
|
|
|
except (TypeError, ValueError):
|
|
|
|
return ''
|
2016-11-10 10:14:51 -07:00
|
|
|
prec = to_format / 1000
|
|
|
|
formatted = format(to_format / 1000000, '.3f')
|
|
|
|
if not prec.is_integer():
|
|
|
|
point = str(prec - int(prec))[2:]
|
|
|
|
formatted = format_html('{0}<small>{1}</small> MHz', formatted, point)
|
2015-07-11 12:25:40 -06:00
|
|
|
return formatted
|