Module: check_mk
Branch: master
Commit: 93c57c2330cad814a3d2aed87e2d6f26f2c40b68
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=93c57c2330cad8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jan 18 15:22:15 2016 +0100
value_to_text() of Dictionaries can now return a custom text when the value is at default
value
---
web/htdocs/valuespec.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 4b40b57..3e77416 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -2771,6 +2771,10 @@ class Dictionary(ValueSpec):
ValueSpec.__init__(self, **kwargs)
self._elements = kwargs["elements"]
self._empty_text = kwargs.get("empty_text", _("(no
parameters)"))
+ # Optionally a text can be specified to be shown by value_to_text()
+ # when the value equal the default value of the value spec. Normally
+ # the default values are shown.
+ self._default_text = kwargs.get("default_text", None)
self._required_keys = kwargs.get("required_keys", [])
self._ignored_keys = kwargs.get("ignored_keys", [])
self._default_keys = kwargs.get("default_keys", []) # keys present in
default value
@@ -2965,6 +2969,9 @@ class Dictionary(ValueSpec):
if not value:
return self._empty_text
+ if self._default_text and value == self.default_value():
+ return self._default_text
+
if not oneline:
s = '<table class=vs_dict_text>'
else: