Module: check_mk
Branch: master
Commit: 12157a769689f3f35c22426987a680264439558a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=12157a769689f3…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Fri Nov 4 11:18:19 2016 +0100
Fixed some bugs with HTML class.
---
web/htdocs/htmllib.py | 12 ++++++++++--
web/htdocs/table.py | 5 +++--
web/htdocs/valuespec.py | 1 +
web/htdocs/wato.py | 22 +++++++++++-----------
web/plugins/views/painters.py | 2 +-
5 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 8187e9b..e5203d6 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -120,6 +120,14 @@ class HTML(object):
return self.value
+ def __unicode__(self):
+ return self.value
+
+
+ def __repr__(self):
+ return "HTML(%s)" % repr(self.value)
+
+
def __add__(self, other):
if isinstance(other, HTML):
return self.value + other.value
@@ -233,7 +241,7 @@ class OutputFunnel(object):
return
if isinstance(text, HTML):
- text = text.value
+ text = "%s" % text
if type(text) not in [str, unicode]: # also possible: type Exception!
raise MKGeneralException(_('Type Error: html.write accepts str and
unicode input objects only!'))
@@ -489,7 +497,7 @@ class HTMLGenerator(OutputFunnel):
def strip_tags(self, ht):
if isinstance(ht, HTML):
- return self.strip_tags(ht.value)
+ ht = "%s" % ht
if type(ht) not in [str, unicode]:
return ht
diff --git a/web/htdocs/table.py b/web/htdocs/table.py
index de478a1..a2cd3b1 100644
--- a/web/htdocs/table.py
+++ b/web/htdocs/table.py
@@ -115,8 +115,9 @@ def cell(*posargs, **kwargs):
next_args = posargs, kwargs
def add_cell(title="", text="", css=None, help=None, colspan=None,
sortable=True):
- if type(text) == HTML:
- text = text.value
+
+ if isinstance(text, HTML):
+ text = "%s" % text
if type(text) != unicode:
text = str(text)
htmlcode = text + html.drain()
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index afda586..d31b346 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -476,6 +476,7 @@ class TextAscii(ValueSpec):
ValueSpec.custom_validate(self, value, varprefix)
+
class TextUnicode(TextAscii):
def __init__(self, **kwargs):
TextAscii.__init__(self, **kwargs)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 5c2ea34..95375d4 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -2307,7 +2307,7 @@ def output_analysed_ruleset(all_rulesets, rulespec, hostname,
service, known_set
elif known_settings is not PARAMETERS_UNKNOWN:
try:
- html.write_text(valuespec.value_to_text(known_settings))
+ html.write(valuespec.value_to_text(known_settings))
except Exception, e:
if config.debug:
raise
@@ -2332,7 +2332,7 @@ def output_analysed_ruleset(all_rulesets, rulespec, hostname,
service, known_set
# If there is a factory default then show that one
elif rulespec["factory_default"] is not NO_FACTORY_DEFAULT:
setting = rulespec["factory_default"]
- html.write_text(valuespec.value_to_text(setting))
+ html.write(valuespec.value_to_text(setting))
# Rulesets that build lists are empty if no rule matches
elif rulespec["match"] in ("all", "list"):
@@ -2340,14 +2340,14 @@ def output_analysed_ruleset(all_rulesets, rulespec, hostname,
service, known_set
# Else we use the default value of the valuespec
else:
- html.write_text(valuespec.value_to_text(valuespec.default_value()))
+ html.write(valuespec.value_to_text(valuespec.default_value()))
# We have a setting
elif valuespec:
if rulespec["match"] in ( "all", "list" ):
- html.write_text(", ".join([valuespec.value_to_text(e) for e in
setting]))
+ html.write(", ".join([valuespec.value_to_text(e) for e in
setting]))
else:
- html.write_text(valuespec.value_to_text(setting))
+ html.write(valuespec.value_to_text(setting))
# Binary rule, no valuespec, outcome is True or False
else:
@@ -6626,7 +6626,7 @@ def mode_edit_configvar(phase, what = 'globalvars'):
if curvalue == defvalue:
html.write_text(_("Your setting and factory settings are
identical."))
else:
- html.write_text(valuespec.value_to_text(defvalue))
+ html.write(valuespec.value_to_text(defvalue))
forms.end()
html.button("save", _("Save"))
@@ -8085,9 +8085,9 @@ def mode_notifications(phase):
table.cell(_("Plugin parameters"), ",
".join(parameters))
table.cell(_("Bulking"))
if bulk:
- html.write_text(_("Time horizon") + ": " +
Age().value_to_text(bulk["interval"]))
+ html.write(_("Time horizon") + ": " +
Age().value_to_text(bulk["interval"]))
html.write_text(", %s: %d" % (_("Maximum count"),
bulk["count"]))
- html.write_text(", %s %s" % (_("group by"),
vs_notification_bulkby().value_to_text(bulk["groupby"])))
+ html.write(", %s %s" % (_("group by"),
vs_notification_bulkby().value_to_text(bulk["groupby"])))
table.end()
@@ -10226,7 +10226,7 @@ def mode_users(phase):
for name, attr in visible_custom_attrs:
vs = attr['valuespec']
table.cell(_u(vs.title()))
- html.write_text(vs.value_to_text(user.get(name, vs.default_value())))
+ html.write(vs.value_to_text(user.get(name, vs.default_value())))
table.end()
@@ -10352,7 +10352,7 @@ def mode_edit_user(phase):
if attr['user_editable'] and not is_locked(name):
vs.render_input("ua_" + name, user.get(name,
vs.default_value()))
else:
- html.write_text(vs.value_to_text(user.get(name, vs.default_value())))
+ html.write(vs.value_to_text(user.get(name, vs.default_value())))
# Render hidden to have the values kept after saving
html.open_div(style="display:none")
vs.render_input("ua_" + name, user.get(name,
vs.default_value()))
@@ -14404,7 +14404,7 @@ def page_user_profile(change_pw=False):
vs.render_input("ua_" + name, value)
html.help(_u(vs.help()))
else:
- html.write_text(vs.value_to_text(value))
+ html.write(vs.value_to_text(value))
# Save button
forms.end()
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index d6c29b3..4b7fb58 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -301,7 +301,7 @@ def process_multisite_icons(what, row, tags, custom_vars, toplevel):
elif type(result) in [str, unicode, HTML]:
if isinstance(result, HTML):
- result = result.value
+ result = "%s" % result
# TODO: This is handling the deprecated API with 1.2.7. Remove this
one day.
if result[0] == '<':