From 01eb5bf8869c41220763ee5fe5e4dec1e48f06bd Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Sat, 27 Jan 2024 23:25:07 -0500 Subject: [PATCH] Adding missing services controller. --- owrx/controllers/services.py | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 owrx/controllers/services.py diff --git a/owrx/controllers/services.py b/owrx/controllers/services.py new file mode 100644 index 00000000..d485bee7 --- /dev/null +++ b/owrx/controllers/services.py @@ -0,0 +1,57 @@ +from owrx.controllers.admin import AuthorizationMixin +from owrx.controllers.template import WebpageController +from owrx.breadcrumb import Breadcrumb, BreadcrumbItem, BreadcrumbMixin +from owrx.service import Services +import json +import re + +import logging + +logger = logging.getLogger(__name__) + + +class ServiceController(AuthorizationMixin, WebpageController): + def indexAction(self): + self.serve_template("services.html", **self.template_variables()) + + def template_variables(self): + variables = super().template_variables() + variables["services"] = self.renderServices() + return variables + + @staticmethod + def renderServices(): + return """ + + + + + + + {services} +
ServiceSDR ProfileFrequency
+ """.format( + services="".join(ServiceController.renderService(c) for c in Services.listAll()) + ) + + @staticmethod + def renderService(c): + # Choose units based on frequency + freq = c["freq"] + if freq >= 1000000000: + freq = freq / 1000000000 + unit = "GHz" + elif freq >= 30000000: + freq = freq / 1000000 + unit = "MHz" + elif freq >= 1000: + freq = freq / 1000 + unit = "kHz" + else: + unit = "Hz" + # Removing trailing zeros + freq = re.sub(r"\.?0+$", "", "{0}".format(freq)) + # Format row + return "{0}{1} {2}{3}{4}".format( + c["mode"].upper(), c["sdr"], c["band"], freq, unit + )