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 ''
|
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)
|
2017-03-25 15:51:08 -06:00
|
|
|
response = format_html('{0} MHz', formatted)
|
2017-03-25 06:22:37 -06:00
|
|
|
return response
|