Module: check_mk
Branch: master
Commit: 3a9b50fe6d426e8066db5f44ce7f76c48424f6a9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3a9b50fe6d426e…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Fri Dec 15 10:15:53 2017 +0100
Refactor the ValueSpec TimeperiodSelection
Refactor the Valuespec TimeperiodSelection to use DropdownChoice instead
of ElementSelection.
Change-Id: I18daf9015f7c237ca8b5dd8439c9db7abd49076a
---
web/htdocs/valuespec.py | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index a163967..d2c6090 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -4621,22 +4621,23 @@ class SiteChoice(DropdownChoice):
return config.site_choices(filter_func=lambda site_id, site: site_id in
authorized_site_ids)
-
-
-class TimeperiodSelection(ElementSelection):
+class TimeperiodSelection(DropdownChoice):
def __init__(self, **kwargs):
- ElementSelection.__init__(self, **kwargs)
+ kwargs.setdefault("default_value", "24X7")
+ DropdownChoice.__init__(self, choices=self._get_choices, **kwargs)
- def get_elements(self):
+ def _get_choices(self):
import watolib
timeperiods = watolib.load_timeperiods()
- elements = dict([ ("24X7", _("Always")) ] + \
- [ (name, "%s - %s" % (name, tp["alias"])) for (name, tp)
in timeperiods.items() ])
- return elements
+ elements = [
+ (name, "%s - %s" % (name, tp["alias"])) for (name, tp) in
timeperiods.items()
+ ]
- def default_value(self):
- return "24x7"
+ always = ("24X7", _("Always"))
+ if always not in elements:
+ elements.insert(0, always)
+ return elements
class TimeperiodValuespec(ValueSpec):