implement some basic infrastructure to present device forms
This commit is contained in:
parent
872c7a4bfd
commit
012952f6f3
23
owrx/controllers/settings/devices/__init__.py
Normal file
23
owrx/controllers/settings/devices/__init__.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from owrx.form import Input
|
||||||
|
from owrx.controllers.settings import Section
|
||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
class SdrDeviceType(ABC):
|
||||||
|
@staticmethod
|
||||||
|
def getByType(sdr_type: str) -> "SdrDeviceType":
|
||||||
|
try:
|
||||||
|
className = "".join(x for x in sdr_type.title() if x.isalnum()) + "DeviceType"
|
||||||
|
module = __import__("owrx.controllers.settings.devices.{0}".format(sdr_type), fromlist=[className])
|
||||||
|
cls = getattr(module, className)
|
||||||
|
return cls()
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def getInputs(self) -> List[Input]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def getSection(self):
|
||||||
|
return Section("Device settings", *self.getInputs())
|
13
owrx/controllers/settings/devices/rtl_sdr.py
Normal file
13
owrx/controllers/settings/devices/rtl_sdr.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from typing import List
|
||||||
|
from owrx.controllers.settings.devices import SdrDeviceType
|
||||||
|
from owrx.form import Input, TextInput
|
||||||
|
|
||||||
|
|
||||||
|
class RtlSdrDeviceType(SdrDeviceType):
|
||||||
|
def getInputs(self) -> List[Input]:
|
||||||
|
return [
|
||||||
|
TextInput(
|
||||||
|
"test",
|
||||||
|
"This is a drill"
|
||||||
|
),
|
||||||
|
]
|
@ -1,5 +1,7 @@
|
|||||||
from owrx.controllers.admin import AuthorizationMixin
|
from owrx.controllers.admin import AuthorizationMixin
|
||||||
from owrx.controllers.template import WebpageController
|
from owrx.controllers.template import WebpageController
|
||||||
|
from owrx.controllers.settings import SettingsFormController
|
||||||
|
from owrx.controllers.settings.devices import SdrDeviceType
|
||||||
from owrx.config import Config
|
from owrx.config import Config
|
||||||
from urllib.parse import quote, unquote
|
from urllib.parse import quote, unquote
|
||||||
|
|
||||||
@ -45,8 +47,22 @@ class SdrDeviceListController(AuthorizationMixin, WebpageController):
|
|||||||
self.serve_template("settings/general.html", **self.template_variables())
|
self.serve_template("settings/general.html", **self.template_variables())
|
||||||
|
|
||||||
|
|
||||||
class SdrDeviceController(AuthorizationMixin, WebpageController):
|
class SdrDeviceController(SettingsFormController):
|
||||||
def get_device(self):
|
def __init__(self, handler, request, options):
|
||||||
|
super().__init__(handler, request, options)
|
||||||
|
self.device = self._get_device()
|
||||||
|
|
||||||
|
def getSections(self):
|
||||||
|
device_type = SdrDeviceType.getByType(self.device["type"])
|
||||||
|
if device_type is None:
|
||||||
|
# TODO provide a generic interface that allows to switch the type
|
||||||
|
return []
|
||||||
|
return [device_type.getSection()]
|
||||||
|
|
||||||
|
def getTitle(self):
|
||||||
|
return self.device["name"]
|
||||||
|
|
||||||
|
def _get_device(self):
|
||||||
device_id = unquote(self.request.matches.group(1))
|
device_id = unquote(self.request.matches.group(1))
|
||||||
if device_id not in Config.get()["sdrs"]:
|
if device_id not in Config.get()["sdrs"]:
|
||||||
return None
|
return None
|
||||||
@ -57,16 +73,13 @@ class SdrDeviceController(AuthorizationMixin, WebpageController):
|
|||||||
variables["assets_prefix"] = "../../"
|
variables["assets_prefix"] = "../../"
|
||||||
return variables
|
return variables
|
||||||
|
|
||||||
def template_variables(self, device):
|
def template_variables(self):
|
||||||
variables = super().template_variables()
|
variables = super().template_variables()
|
||||||
variables["title"] = device["name"]
|
|
||||||
variables["content"] = "TODO"
|
|
||||||
variables["assets_prefix"] = "../../"
|
variables["assets_prefix"] = "../../"
|
||||||
return variables
|
return variables
|
||||||
|
|
||||||
def indexAction(self):
|
def indexAction(self):
|
||||||
device = self.get_device()
|
if self.device is None:
|
||||||
if device is None:
|
|
||||||
self.send_response("device not found", code=404)
|
self.send_response("device not found", code=404)
|
||||||
return
|
return
|
||||||
self.serve_template("settings/general.html", **self.template_variables(device))
|
self.serve_template("settings/general.html", **self.template_variables())
|
||||||
|
@ -71,7 +71,7 @@ class SdrService(object):
|
|||||||
def getSources():
|
def getSources():
|
||||||
SdrService._loadProps()
|
SdrService._loadProps()
|
||||||
for id in SdrService.sdrProps.keys():
|
for id in SdrService.sdrProps.keys():
|
||||||
if not id in SdrService.sources:
|
if id not in SdrService.sources:
|
||||||
props = SdrService.sdrProps[id]
|
props = SdrService.sdrProps[id]
|
||||||
sdrType = props["type"]
|
sdrType = props["type"]
|
||||||
className = "".join(x for x in sdrType.title() if x.isalnum()) + "Source"
|
className = "".join(x for x in sdrType.title() if x.isalnum()) + "Source"
|
||||||
|
Loading…
Reference in New Issue
Block a user