From 29566430a66b652c6ae4cb483d1d692166c95aa4 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sun, 29 Mar 2020 20:49:37 +0200 Subject: [PATCH] add location input fields --- owrx/form/__init__.py | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/owrx/form/__init__.py b/owrx/form/__init__.py index 2ba65ea..399665a 100644 --- a/owrx/form/__init__.py +++ b/owrx/form/__init__.py @@ -48,11 +48,19 @@ class TextInput(Input): class NumberInput(Input): + def __init__(self, id, label, infotext=None): + super().__init__(id, label, infotext) + self.step = None + def render_input(self, value): return """ - + """.format( - id=self.id, label=self.label, classes=self.input_classes(), value=value + id=self.id, + label=self.label, + classes=self.input_classes(), + value=value, + step='step="{0}"'.format(self.step) if self.step else "", ) def convert_value(self, v): @@ -63,6 +71,10 @@ class NumberInput(Input): class FloatInput(NumberInput): + def __init__(self, id, label, infotext=None): + super().__init__(id, label, infotext) + self.step = "any" + def convert_value(self, v): return float(v) @@ -70,7 +82,30 @@ class FloatInput(NumberInput): class LocationInput(Input): def render_input(self, value): # TODO make this work and pretty - return "Placeholder for a map widget to select receiver location" + return """ +
+ {inputs} +
+ """.format( + inputs="".join(self.render_sub_input(value, id) for id in ["lat", "lon"]) + ) + + def render_sub_input(self, value, id): + return """ +
+ +
+ """.format( + id="{0}-{1}".format(self.id, id), + label=self.label, + classes=self.input_classes(), + value=value[id], + ) + + def parse(self, data): + return { + self.id: {k: float(data["{0}-{1}".format(self.id, k)][0]) for k in ["lat", "lon"]} + } class TextAreaInput(Input):