use a converter -> parsing done

This commit is contained in:
Jakob Ketterl 2021-02-15 22:22:07 +01:00
parent 1112334ea8
commit c2617fcfaf
2 changed files with 12 additions and 1 deletions

View File

@ -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)

View File

@ -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)),
)