2021-02-15 14:29:02 +00:00
|
|
|
from owrx.controllers.admin import AuthorizationMixin
|
|
|
|
from owrx.controllers.template import WebpageController
|
|
|
|
from owrx.config import Config
|
2021-02-18 23:03:25 +00:00
|
|
|
from urllib.parse import quote, unquote
|
2021-02-15 14:29:02 +00:00
|
|
|
|
|
|
|
|
2021-02-18 23:03:25 +00:00
|
|
|
class SdrDeviceListController(AuthorizationMixin, WebpageController):
|
2021-02-15 14:29:02 +00:00
|
|
|
def header_variables(self):
|
|
|
|
variables = super().header_variables()
|
|
|
|
variables["assets_prefix"] = "../"
|
|
|
|
return variables
|
|
|
|
|
|
|
|
def template_variables(self):
|
|
|
|
variables = super().template_variables()
|
2021-02-18 22:05:43 +00:00
|
|
|
variables["content"] = self.render_devices()
|
2021-02-18 21:12:13 +00:00
|
|
|
variables["title"] = "SDR device settings"
|
2021-02-18 23:03:25 +00:00
|
|
|
variables["assets_prefix"] = "../"
|
2021-02-15 14:29:02 +00:00
|
|
|
return variables
|
|
|
|
|
|
|
|
def render_devices(self):
|
2021-02-18 22:05:43 +00:00
|
|
|
def render_device(device_id, config):
|
|
|
|
return """
|
2021-02-18 23:03:25 +00:00
|
|
|
<li class="list-group-item">
|
|
|
|
<a href="{device_link}">
|
|
|
|
<h3>{device_name}</h3>
|
|
|
|
</a>
|
|
|
|
<div>
|
|
|
|
some more device info here
|
2021-02-15 14:29:02 +00:00
|
|
|
</div>
|
2021-02-18 23:03:25 +00:00
|
|
|
</li>
|
2021-02-15 14:29:02 +00:00
|
|
|
""".format(
|
2021-02-18 23:03:25 +00:00
|
|
|
device_name=config["name"],
|
|
|
|
device_link="{}/{}".format(self.request.path, quote(device_id)),
|
2021-02-18 22:05:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return """
|
2021-02-18 23:03:25 +00:00
|
|
|
<ul class="row list-group list-group-flush sdr-device-list">
|
2021-02-18 22:05:43 +00:00
|
|
|
{devices}
|
2021-02-18 23:03:25 +00:00
|
|
|
</ul>
|
2021-02-18 22:05:43 +00:00
|
|
|
""".format(
|
|
|
|
devices="".join(render_device(key, value) for key, value in Config.get()["sdrs"].items())
|
2021-02-15 14:29:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def indexAction(self):
|
2021-02-18 21:12:13 +00:00
|
|
|
self.serve_template("settings/general.html", **self.template_variables())
|
2021-02-18 23:03:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SdrDeviceController(AuthorizationMixin, WebpageController):
|
|
|
|
def get_device(self):
|
|
|
|
device_id = unquote(self.request.matches.group(1))
|
|
|
|
if device_id not in Config.get()["sdrs"]:
|
|
|
|
return None
|
|
|
|
return Config.get()["sdrs"][device_id]
|
|
|
|
|
|
|
|
def header_variables(self):
|
|
|
|
variables = super().header_variables()
|
|
|
|
variables["assets_prefix"] = "../../"
|
|
|
|
return variables
|
|
|
|
|
|
|
|
def template_variables(self, device):
|
|
|
|
variables = super().template_variables()
|
|
|
|
variables["title"] = device["name"]
|
|
|
|
variables["content"] = "TODO"
|
|
|
|
variables["assets_prefix"] = "../../"
|
|
|
|
return variables
|
|
|
|
|
|
|
|
def indexAction(self):
|
|
|
|
device = self.get_device()
|
|
|
|
if device is None:
|
|
|
|
self.send_response("device not found", code=404)
|
|
|
|
return
|
|
|
|
self.serve_template("settings/general.html", **self.template_variables(device))
|