Module: check_mk
Branch: master
Commit: 016fd7c3537c87caed2246c3b87f98c26ce028a2
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=016fd7c3537c87…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Jun 3 11:21:28 2012 +0200
ValueSpec ElementSelection: allow label and none-selection
---
web/htdocs/valuespec.py | 3 +++
web/htdocs/wato.py | 7 ++++++-
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index a80f9ef..2b9a4c0 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1814,6 +1814,7 @@ class ElementSelection(ValueSpec):
def __init__(self, **kwargs):
ValueSpec.__init__(self, **kwargs)
self._loaded_at = None
+ self._label = kwargs.get("label")
def load_elements(self):
if self._loaded_at != id(html):
@@ -1833,6 +1834,8 @@ class ElementSelection(ValueSpec):
if len(self._elements) == 0:
html.write(_("There are not defined any elements for this selection
yet."))
else:
+ if self._label:
+ html.write("%s " % self._label)
html.sorted_select(varprefix, self._elements.items(), value)
def value_to_text(self, value):
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 5e5be3e..b9e22dd 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -5680,12 +5680,17 @@ class GroupSelection(ElementSelection):
def __init__(self, what, **kwargs):
ElementSelection.__init__(self, **kwargs)
self._what = what
+ # Allow to have "none" entry with the following title
+ self._no_selection = kwargs.get("no_selection")
def get_elements(self):
all_groups = load_group_information()
this_group = all_groups.get(self._what, {})
# replace the title with the key if the title is empty
- return dict([ (k, t and t or k) for (k, t) in this_group.items() ])
+ elements = [ (k, t and t or k) for (k, t) in this_group.items() ]
+ if self._no_selection:
+ elements.append((None, self._no_selection))
+ return dict(elements)
class CheckTypeGroupSelection(ElementSelection):