add receiver_keys to the settings page

This commit is contained in:
Jakob Ketterl 2021-02-07 18:04:46 +01:00
parent 25db7c716d
commit 8de70cd523
2 changed files with 30 additions and 8 deletions

View File

@ -12,6 +12,7 @@ from owrx.form import (
Option,
ServicesCheckboxInput,
Js8ProfileCheckboxInput,
ReceiverKeysInput,
)
from urllib.parse import quote
import json
@ -100,6 +101,15 @@ class GeneralSettingsController(AdminController):
TextInput("photo_title", "Photo title"),
TextAreaInput("photo_desc", "Photo description"),
),
Section(
"Receiver listings",
ReceiverKeysInput(
"receiver_keys",
"Receiver keys",
infotext="Put the keys you receive on listing sites (e.g. "
+ '<a href="https://www.receiverbook.de">Receiverbook</a>) here, one per line',
),
),
Section(
"Waterfall settings",
NumberInput(
@ -294,4 +304,4 @@ class GeneralSettingsController(AdminController):
for k, v in data.items():
config[k] = v
Config.store()
self.send_redirect("/admin")
self.send_redirect("/generalsettings")

View File

@ -30,11 +30,17 @@ class Input(ABC):
def render_input(self, value):
pass
def convert_to_form(self, value):
return value
def convert_from_form(self, value):
return value
def render(self, config):
return self.bootstrap_decorate(self.render_input(config[self.id]))
return self.bootstrap_decorate(self.render_input(self.convert_to_form(config[self.id])))
def parse(self, data):
return {self.id: data[self.id][0]} if self.id in data else {}
return {self.id: self.convert_from_form(data[self.id][0])} if self.id in data else {}
class TextInput(Input):
@ -62,19 +68,16 @@ class NumberInput(Input):
step='step="{0}"'.format(self.step) if self.step else "",
)
def convert_value(self, v):
def convert_from_form(self, v):
return int(v)
def parse(self, data):
return {k: self.convert_value(v) for k, v in super().parse(data).items()}
class FloatInput(NumberInput):
def __init__(self, id, label, infotext=None):
super().__init__(id, label, infotext)
self.step = "any"
def convert_value(self, v):
def convert_from_form(self, v):
return float(v)
@ -118,6 +121,15 @@ class TextAreaInput(Input):
)
class ReceiverKeysInput(TextAreaInput):
def convert_to_form(self, value):
return "\n".join(value)
def convert_from_form(self, value):
# \r\n or \n? this should work with both.
return [v.strip("\r ") for v in value.split("\n")]
class CheckboxInput(Input):
def __init__(self, id, label, checkboxText, infotext=None):
super().__init__(id, label, infotext=infotext)