From c2617fcfaf2bc375028f7cf2878ee18689e43fc1 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Mon, 15 Feb 2021 22:22:07 +0100 Subject: [PATCH] use a converter -> parsing done --- owrx/form/converter.py | 7 +++++++ owrx/form/wsjt.py | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/owrx/form/converter.py b/owrx/form/converter.py index 7739591..7997cd9 100644 --- a/owrx/form/converter.py +++ b/owrx/form/converter.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod +import json class Converter(ABC): @@ -59,3 +60,9 @@ class EnumConverter(Converter): return self.enumCls[value].value +class JsonConverter(Converter): + def convert_to_form(self, value): + return json.dumps(value) + + def convert_from_form(self, value): + return json.loads(value) diff --git a/owrx/form/wsjt.py b/owrx/form/wsjt.py index ec79654..52bd50f 100644 --- a/owrx/form/wsjt.py +++ b/owrx/form/wsjt.py @@ -1,4 +1,5 @@ from owrx.form import Input +from owrx.form.converter import JsonConverter from owrx.wsjt import Q65Mode, Q65Interval from owrx.modes import Modes, WsjtMode import json @@ -56,6 +57,9 @@ class Q65ModeMatrix(Input): class WsjtDecodingDepthsInput(Input): + def defaultConverter(self): + return JsonConverter() + def render_input(self, value): def render_mode(m): return """ @@ -74,7 +78,7 @@ class WsjtDecodingDepthsInput(Input): """.format( id=self.id, classes=self.input_classes(), - value=html.escape(json.dumps(value)), + value=html.escape(value), options="".join(render_mode(m) for m in Modes.getAvailableModes() if isinstance(m, WsjtMode)), )