dict valuespecs, encoding regexp chars correctly when displaying
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 0d16d572ea0d76cdbb911284b6fca398c9804f0e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0d16d572ea0d76…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 14 09:48:11 2012 +0200
WATO: Improved visualization of list/dict valuespecs, encoding regexp chars correctly when
displaying
---
ChangeLog | 2 ++
web/htdocs/valuespec.py | 30 ++++++++++++++++++++++--------
web/plugins/wato/check_parameters.py | 3 ++-
3 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 01b9b1a..f061fdc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -75,6 +75,8 @@
unreachable gateways.
* User managament: Added fields for editing host/service notification commands
* Added new active check configuration for check_smtp
+ * Improved visualization of ruleset lists/dictionaries
+ * Encoding special chars in RegExp valuespec (e.g. logwatch patterns)
* FIX: Removed double collect_hosts() call in activate changes hook
* FIX: Fixed double hook execution when using localized multisite
* FIX: User list shows names of contactgroups when no alias given
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index afff6b0..b78cb32 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -26,12 +26,14 @@
import math, os, time, re, sre_constants, urlparse, forms
from lib import *
+from htmllib import attrencode
# Abstract base class of all value declaration classes.
class ValueSpec:
def __init__(self, **kwargs):
self._title = kwargs.get("title")
self._help = kwargs.get("help")
+ self._attrencode = kwargs.get("attrencode", False)
if "default_value" in kwargs:
self._default_value = kwargs.get("default_value")
@@ -74,6 +76,10 @@ class ValueSpec:
# used in tables and other contextes. It is to be read
# by the user and need not to be parsable.
# The function may assume that the type of the value is valid.
+ #
+ # In the current implementation this function is only used to
+ # render the object for html code. So it is allowed to add
+ # html code for better layout in the GUI.
def value_to_text(self, value):
return repr(value)
@@ -303,7 +309,10 @@ class TextAscii(ValueSpec):
if value == None:
return _("none")
else:
- return value
+ if self._attrencode:
+ return attrencode(value)
+ else:
+ return value
def from_html_vars(self, varprefix):
value = html.var(varprefix, "")
@@ -340,7 +349,7 @@ class ID(TextAscii):
class RegExp(TextAscii):
def __init__(self, **kwargs):
- TextAscii.__init__(self, **kwargs)
+ TextAscii.__init__(self, attrencode = True, **kwargs)
def validate_value(self, value, varprefix):
TextAscii.validate_value(self, value, varprefix)
@@ -535,7 +544,10 @@ class ListOfStrings(ValueSpec):
return []
def value_to_text(self, value):
- return ", ".join([self._valuespec.value_to_text(v) for v in value])
+ s = '<table>'
+ for v in value:
+ s += '<tr><td>%s</td></tr>' %
self._valuespec.value_to_text(v)
+ return s + '</table>'
def from_html_vars(self, vp):
value = []
@@ -647,8 +659,10 @@ class ListOf(ValueSpec):
else:
return self._totext
else:
- return ", ".join([
- self._valuespec.value_to_text(v) for v in value])
+ s = '<table>'
+ for v in value:
+ s += '<tr><td>%s</td></tr>' %
self._valuespec.value_to_text(v)
+ return s + '</table>'
def from_html_vars(self, varprefix):
n = 1
@@ -1814,11 +1828,11 @@ class Dictionary(ValueSpec):
if not value:
return self._empty_text
- parts = []
+ s = '<table>'
for param, vs in self._elements:
if param in value:
- parts.append("%s: %s" % (vs.title(),
vs.value_to_text(value[param])))
- return ", ".join(parts)
+ s +=
"<tr><td>%s</td><td>%s</td></tr>" %
(vs.title(), vs.value_to_text(value[param]))
+ return s + '</table>'
def from_html_vars(self, varprefix):
value = {}
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 812fca0..328239c 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -111,10 +111,11 @@ register_rule(group + '/' + subgroup_applications,
),
RegExp(
title = _("Pattern (Regex)"),
- size = 20,
+ size = 40,
),
TextAscii(
title = _("Comment"),
+ size = 40,
),
]
),