2019-11-22 11:23:24 -07:00
|
|
|
"""Django template tags for SatNOGS Network"""
|
2014-09-01 11:06:51 -06:00
|
|
|
from django import template
|
2015-07-11 15:37:51 -06:00
|
|
|
from django.core.urlresolvers import reverse
|
2014-09-01 11:06:51 -06:00
|
|
|
|
|
|
|
register = template.Library()
|
|
|
|
|
2014-09-01 14:31:22 -06:00
|
|
|
|
2014-09-01 11:06:51 -06:00
|
|
|
@register.simple_tag
|
2015-07-11 15:37:51 -06:00
|
|
|
def active(request, urls):
|
2019-11-22 11:23:24 -07:00
|
|
|
"""Returns if this is an active URL"""
|
2015-07-21 02:42:40 -06:00
|
|
|
if request.path in (reverse(url) for url in urls.split()):
|
2014-09-01 11:06:51 -06:00
|
|
|
return 'active'
|
2014-09-01 14:31:22 -06:00
|
|
|
return None
|
2014-10-27 09:47:32 -06:00
|
|
|
|
|
|
|
|
2019-06-09 15:46:38 -06:00
|
|
|
@register.simple_tag
|
|
|
|
def drifted_frq(frq, drift):
|
2019-11-22 11:23:24 -07:00
|
|
|
"""Returns drifred frequency"""
|
2019-06-09 15:46:38 -06:00
|
|
|
return int(round(frq + ((frq * drift) / float(pow(10, 9)))))
|
|
|
|
|
|
|
|
|
2015-07-11 15:38:48 -06:00
|
|
|
@register.filter
|
2014-10-27 09:47:32 -06:00
|
|
|
def frq(value):
|
2019-11-22 11:23:24 -07:00
|
|
|
"""Returns Hz formatted frequency html string"""
|
2015-07-11 15:38:48 -06:00
|
|
|
try:
|
|
|
|
to_format = float(value)
|
2015-07-23 09:18:01 -06:00
|
|
|
except (TypeError, ValueError):
|
2015-07-11 15:38:48 -06:00
|
|
|
return '-'
|
2014-10-27 09:47:32 -06:00
|
|
|
formatted = format(float(to_format) / 1000000, '.3f')
|
2015-08-15 05:07:31 -06:00
|
|
|
formatted = formatted + ' MHz'
|
2014-10-27 09:47:32 -06:00
|
|
|
return formatted
|
2015-08-11 03:19:10 -06:00
|
|
|
|
|
|
|
|
|
|
|
@register.filter
|
|
|
|
def percentagerest(value):
|
2019-11-22 11:23:24 -07:00
|
|
|
"""Returns the rest of percentage from a given (percentage) value"""
|
2015-08-11 03:19:10 -06:00
|
|
|
try:
|
|
|
|
return 100 - value
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
return 0
|
2016-05-09 06:29:23 -06:00
|
|
|
|
|
|
|
|
2018-10-15 12:48:56 -06:00
|
|
|
@register.filter
|
|
|
|
def sortdemoddata(demoddata):
|
2019-11-22 11:23:24 -07:00
|
|
|
"""Returns a date sorted list of DemodData"""
|
2018-10-15 12:48:56 -06:00
|
|
|
try:
|
|
|
|
return sorted(list(demoddata), key=lambda x: str(x.payload_demod).split('/', 2)[2:])
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
return demoddata
|