add sdr.hu settings
This commit is contained in:
parent
df21a1eed6
commit
6493fb86c1
@ -13,11 +13,6 @@ ${header}
|
|||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<h1>Settings</h1>
|
<h1>Settings</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 settings-category">
|
${sections}
|
||||||
<h3 class="settings-header">
|
|
||||||
General Settings
|
|
||||||
</h3>
|
|
||||||
${form}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
@ -112,6 +112,7 @@ class OpenWebRxReceiverClient(Client):
|
|||||||
receiver_info["locator"] = Locator.fromCoordinates(receiver_info["receiver_gps"])
|
receiver_info["locator"] = Locator.fromCoordinates(receiver_info["receiver_gps"])
|
||||||
self.write_receiver_details(receiver_info)
|
self.write_receiver_details(receiver_info)
|
||||||
|
|
||||||
|
# TODO unsubscribe
|
||||||
receiver_details.wire(send_receiver_info)
|
receiver_details.wire(send_receiver_info)
|
||||||
send_receiver_info()
|
send_receiver_info()
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class Input(ABC):
|
|||||||
def render(self, config):
|
def render(self, config):
|
||||||
return self.bootstrap_decorate(self.render_input(config[self.id]))
|
return self.bootstrap_decorate(self.render_input(config[self.id]))
|
||||||
|
|
||||||
def validate(self, data):
|
def parse(self, data):
|
||||||
return {self.id: data[self.id][0]} if self.id in data else {}
|
return {self.id: data[self.id][0]} if self.id in data else {}
|
||||||
|
|
||||||
|
|
||||||
@ -59,40 +59,93 @@ class TextAreaInput(Input):
|
|||||||
""".format(id=self.id, classes=self.input_classes(), value=value)
|
""".format(id=self.id, classes=self.input_classes(), value=value)
|
||||||
|
|
||||||
|
|
||||||
|
class CheckboxInput(Input):
|
||||||
|
def __init__(self, id, label, checkboxText, infotext=None):
|
||||||
|
super().__init__(id, label, infotext=infotext)
|
||||||
|
self.checkboxText = checkboxText
|
||||||
|
|
||||||
|
def render_input(self, value):
|
||||||
|
return """
|
||||||
|
<div class="{classes}">
|
||||||
|
<input class="form-check-input" type="checkbox" id="{id}" name="{id}" {checked}>
|
||||||
|
<label class="form-check-label" for="{id}">
|
||||||
|
{checkboxText}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
""".format(id=self.id, classes=self.input_classes(), checked="checked" if value else "", checkboxText=self.checkboxText)
|
||||||
|
|
||||||
|
def input_classes(self):
|
||||||
|
return " ".join(["form-check", "form-control-sm"])
|
||||||
|
|
||||||
|
def parse(self, data):
|
||||||
|
return {self.id: self.id in data and data[self.id][0] == "on"}
|
||||||
|
|
||||||
|
|
||||||
|
class Section(object):
|
||||||
|
def __init__(self, title, *inputs):
|
||||||
|
self.title = title
|
||||||
|
self.inputs = inputs
|
||||||
|
|
||||||
|
def render_inputs(self):
|
||||||
|
config = Config.get()
|
||||||
|
return "".join([i.render(config) for i in self.inputs])
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
return """
|
||||||
|
<div class="col-12 settings-category">
|
||||||
|
<h3 class="settings-header">
|
||||||
|
{title}
|
||||||
|
</h3>
|
||||||
|
{inputs}
|
||||||
|
</div>
|
||||||
|
""".format(title=self.title, inputs=self.render_inputs())
|
||||||
|
|
||||||
|
def parse(self, data):
|
||||||
|
return {k: v for i in self.inputs for k, v in i.parse(data).items()}
|
||||||
|
|
||||||
|
|
||||||
class SettingsController(AdminController):
|
class SettingsController(AdminController):
|
||||||
inputs = [
|
sections = [
|
||||||
|
Section(
|
||||||
|
"General Settings",
|
||||||
TextInput("receiver_name", "Receiver name"),
|
TextInput("receiver_name", "Receiver name"),
|
||||||
TextInput("receiver_location", "Receiver location"),
|
TextInput("receiver_location", "Receiver location"),
|
||||||
TextInput("receiver_asl", "Receiver elevation", infotext="Elevation in meters above mean see level"),
|
TextInput("receiver_asl", "Receiver elevation", infotext="Elevation in meters above mean see level"),
|
||||||
TextInput("receiver_admin", "Receiver admin"),
|
TextInput("receiver_admin", "Receiver admin"),
|
||||||
LocationInput("receiver_gps", "Receiver coordinates"),
|
LocationInput("receiver_gps", "Receiver coordinates"),
|
||||||
TextInput("photo_title", "Photo title"),
|
TextInput("photo_title", "Photo title"),
|
||||||
TextAreaInput("photo_desc", "Photo description")
|
TextAreaInput("photo_desc", "Photo description"),
|
||||||
|
),
|
||||||
|
Section(
|
||||||
|
"sdr.hu",
|
||||||
|
TextInput("sdrhu_key", "sdr.hu key", infotext="Please obtain your personal key on <a href=\"https://sdr.hu\">sdr.hu</a>"),
|
||||||
|
CheckboxInput("sdrhu_public_listing", "List on sdr.hu", "List msy receiver on sdr.hu"),
|
||||||
|
TextInput("server_hostname", "Hostname"),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
def indexAction(self):
|
def render_sections(self):
|
||||||
self.serve_template("admin.html", **self.template_variables())
|
sections = "".join(section.render() for section in SettingsController.sections)
|
||||||
|
|
||||||
def render_form(self):
|
|
||||||
config = Config.get()
|
|
||||||
inputs = "".join([i.render(config) for i in SettingsController.inputs])
|
|
||||||
return """
|
return """
|
||||||
<form class="settings-body" method="POST">
|
<form class="settings-body" method="POST">
|
||||||
{inputs}
|
{sections}
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button type="submit" class="btn btn-primary">Apply</button>
|
<button type="submit" class="btn btn-primary">Apply</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
""".format(inputs=inputs)
|
""".format(sections=sections)
|
||||||
|
|
||||||
|
def indexAction(self):
|
||||||
|
self.serve_template("admin.html", **self.template_variables())
|
||||||
|
|
||||||
def template_variables(self):
|
def template_variables(self):
|
||||||
variables = super().template_variables()
|
variables = super().template_variables()
|
||||||
variables["form"] = self.render_form()
|
variables["sections"] = self.render_sections()
|
||||||
return variables
|
return variables
|
||||||
|
|
||||||
def processFormData(self):
|
def processFormData(self):
|
||||||
data = parse_qs(self.get_body().decode("utf-8"))
|
data = parse_qs(self.get_body().decode("utf-8"))
|
||||||
data = {k: v for i in SettingsController.inputs for k, v in i.validate(data).items()}
|
data = {k: v for i in SettingsController.sections for k, v in i.parse(data).items()}
|
||||||
config = Config.get()
|
config = Config.get()
|
||||||
for k, v in data.items():
|
for k, v in data.items():
|
||||||
config[k] = v
|
config[k] = v
|
||||||
|
Loading…
Reference in New Issue
Block a user