From b8808ac8b06af1d42a068c2a59db07950d27f427 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Mon, 15 May 2023 18:40:07 +0200 Subject: [PATCH 1/2] improve the receiver keys input * use the improved input rendering * disable word wrap * omit empty keys --- owrx/controllers/settings/general.py | 7 ++----- owrx/form/input/__init__.py | 13 +++++++++---- owrx/form/input/receiverid.py | 25 ++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/owrx/controllers/settings/general.py b/owrx/controllers/settings/general.py index 231a3c00..e8ccea90 100644 --- a/owrx/controllers/settings/general.py +++ b/owrx/controllers/settings/general.py @@ -11,7 +11,7 @@ from owrx.form.input import ( Option, ) from owrx.form.input.converter import WaterfallColorsConverter, IntConverter -from owrx.form.input.receiverid import ReceiverKeysConverter +from owrx.form.input.receiverid import ReceiverKeysInput from owrx.form.input.gfx import AvatarInput, TopPhotoInput from owrx.form.input.device import WaterfallLevelsInput, WaterfallAutoLevelsInput from owrx.form.input.location import LocationInput @@ -75,12 +75,9 @@ class GeneralSettingsController(SettingsFormController): ), Section( "Receiver listings", - TextAreaInput( + ReceiverKeysInput( "receiver_keys", "Receiver keys", - converter=ReceiverKeysConverter(), - infotext="Put the keys you receive on listing sites (e.g. " - + 'Receiverbook) here, one per line', ), ), Section( diff --git a/owrx/form/input/__init__.py b/owrx/form/input/__init__.py index 06a3d79c..57e59b7a 100644 --- a/owrx/form/input/__init__.py +++ b/owrx/form/input/__init__.py @@ -163,14 +163,19 @@ class FloatInput(NumberInput): class TextAreaInput(Input): def render_input(self, value, errors): return """ - + """.format( - id=self.id, - classes=self.input_classes(errors), + properties=self.render_input_properties(value, errors), value=value, - disabled="disabled" if self.disabled else "", ) + def input_properties(self, value, errors): + props = super().input_properties(value, errors) + props["style"] = "height:200px;" + # value works differently on textareas + del props["value"] + return props + class CheckboxInput(Input): def __init__(self, id, checkboxText, infotext=None, converter: Converter = None): diff --git a/owrx/form/input/receiverid.py b/owrx/form/input/receiverid.py index 0812cc6d..43c0a5de 100644 --- a/owrx/form/input/receiverid.py +++ b/owrx/form/input/receiverid.py @@ -1,3 +1,4 @@ +from owrx.form.input import TextAreaInput from owrx.form.input.converter import Converter @@ -7,4 +8,26 @@ class ReceiverKeysConverter(Converter): 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")] + stripped = [v.strip("\r ") for v in value.split("\n")] + # omit empty lines + return [v for v in stripped if v] + + +class ReceiverKeysInput(TextAreaInput): + def __init__(self, id, label): + super().__init__( + id, + label, + infotext="Put the keys you receive on listing sites (e.g. " + + 'Receiverbook) here, one per line', + ) + + def input_properties(self, value, errors): + props = super().input_properties(value, errors) + # disable word wrap on the textarea. + # why? keys are longer than the input, and word wrap makes the "one per line" instruction confusing. + props["wrap"] = "off" + return props + + def defaultConverter(self): + return ReceiverKeysConverter() From 542f5db58e3ece94a058172804152a6309e8c2f3 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Mon, 15 May 2023 19:00:17 +0200 Subject: [PATCH 2/2] improve config version check --- owrx/config/migration.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/owrx/config/migration.py b/owrx/config/migration.py index 5c97eeeb..856d2709 100644 --- a/owrx/config/migration.py +++ b/owrx/config/migration.py @@ -140,7 +140,11 @@ class Migrator(object): def migrate(config): version = config["version"] if "version" in config else 1 if version == Migrator.currentVersion: - return config + return + elif version > Migrator.currentVersion: + raise ValueError( + "Configuration version is too high (current: {}, found: {})".format(Migrator.currentVersion, version) + ) logger.debug("migrating config from version %i", version) migrators = [Migrator.migrators[i] for i in range(version, Migrator.currentVersion)]