Module: check_mk
Branch: master
Commit: b7f396d93525fc1932dcf58c99cd53ce5a23d85e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b7f396d93525fc…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Dec 30 18:58:59 2011 +0100
Separator for Dropdown Choice
---
web/htdocs/forms.py | 2 +-
web/htdocs/valuespec.py | 11 +++++++++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/web/htdocs/forms.py b/web/htdocs/forms.py
index 7ad903e..aab1955 100644
--- a/web/htdocs/forms.py
+++ b/web/htdocs/forms.py
@@ -28,7 +28,7 @@ from lib import *
def edit_dictionary(entries, value):
- new_value = {}
+ new_value = value.copy()
if html.check_transaction():
messages = []
for name, vs in entries:
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 2c5d11f..13e03c8 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -362,11 +362,15 @@ class Checkbox(ValueSpec):
if type(value) != bool:
raise MKUserError(varprefix, _("The value has type %s, but must be
either True or False") % (type(value)))
-# A type-save dropdown choice
+# A type-save dropdown choice. Parameters:
+# help_separator: if you set this to a character, e.g. "-", then
+# value_to_text will omit texts from the character up to the end of
+# a choices name.
class DropdownChoice(ValueSpec):
def __init__(self, **kwargs):
ValueSpec.__init__(self, **kwargs)
self._choices = kwargs["choices"]
+ self._help_separator = kwargs.get("help_separator")
def canonical_value(self):
return self._choices[0][0]
@@ -384,7 +388,10 @@ class DropdownChoice(ValueSpec):
def value_to_text(self, value):
for val, title in self._choices:
if value == val:
- return title
+ if self._help_separator:
+ return title.split(self._help_separator, 1)[0].strip()
+ else:
+ return title
def from_html_vars(self, varprefix):
sel = html.var(varprefix)