From 33a942707c21c7933c11ecd4f3aa928b398325eb Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Mon, 17 May 2021 23:23:25 +0200 Subject: [PATCH] allow slots to be off in the daylight scheduler --- owrx/form/input/device.py | 41 +++++++++++++++++++++++++-------------- owrx/service/schedule.py | 2 +- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/owrx/form/input/device.py b/owrx/form/input/device.py index 358886f..9e1415e 100644 --- a/owrx/form/input/device.py +++ b/owrx/form/input/device.py @@ -42,9 +42,7 @@ class GainInput(Input): {errors} """.format( - id=self.id, - input=self.render_input(value, errors), - errors=self.render_errors(errors) + id=self.id, input=self.render_input(value, errors), errors=self.render_errors(errors) ) def render_options(self, value): @@ -187,11 +185,28 @@ class SchedulerInput(Input): self.profiles = config["profiles"] return super().render(config, errors) - def render_profiles_select(self, value, errors, config_key, stage, extra_classes=""): + def render_profiles_select(self, value, errors, config_key, stage, extra_classes="", allow_empty=False): stage_value = "" if value and "schedule" in value and config_key in value["schedule"]: stage_value = value["schedule"][config_key] + options = "".join( + """ + + """.format( + id=p_id, + name=p["name"], + selected="selected" if stage_value == p_id else "", + ) + for p_id, p in self.profiles.items() + ) + + if allow_empty: + # prepend a special "off" option to allow a schedule slot to go unused (daylight scheduler) + options = """""".format( + selected="selected" if value is None else "" + ) + options + return """