Module: check_mk
Branch: master
Commit: 239abd0aa64594e859ab5b54dea8bfd3a3821980
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=239abd0aa64594…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Mar 12 15:20:15 2012 +0100
ValueSpec Tuple: fix complain handling
---
web/htdocs/valuespec.py | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 602dbd9..09b610f 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -563,9 +563,6 @@ class ListOf(ValueSpec):
# numbering in labels, etc. possible). The current number
# of entries is stored in the hidden variable 'varprefix'
def render_input(self, varprefix, value):
- if html.has_var(varprefix + "_count"): # already filled in, complain
- value = self.from_html_vars(varprefix)
-
html.write('<input type=hidden name="%s_count" value="%d" id="%s_count">\n' %
(varprefix, len(value), varprefix))
@@ -584,6 +581,12 @@ class ListOf(ValueSpec):
# Actual table of currently existing entries
html.write('<table class="valuespec_listof" id="%s_table">' % varprefix)
+ if html.has_var(varprefix + "_count"): # already filled in, complain
+ value = [None] * int(html.var(varprefix + "_count"))
+ # the underlying render_input-functions should ignore the
+ # value in this case themselves, so that the "None" should not
+ # harm here.
+
for nr, v in enumerate(value):
html.push_transformation(lambda x: x.replace(self._magic, str(nr+1)))
html.write('<tr><td class=vlof_buttons>')
@@ -1351,6 +1354,12 @@ class Tuple(ValueSpec):
html.write('<table class="valuespec_tuple">')
if not self._vertical:
html.write("<tr>")
+
+ # If the form is already filled in and we are in complain mode,
+ # the value in value must be ignored
+ if html.form_filled_in():
+ value = (None,) * len(self._elements)
+
for no, (element, val) in enumerate(zip(self._elements, value)):
vp = varprefix + "_" + str(no)
if element.help():
Module: check_mk
Branch: master
Commit: b020459e54b25113faaf4a74bcfcf2e526ec55c1
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b020459e54b251…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Mar 12 14:40:19 2012 +0100
New ValueSpec for IPv4 Network
---
web/htdocs/valuespec.py | 43 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index d43887e..5bd8b5b 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -328,6 +328,49 @@ class EmailAddress(TextAscii):
def value_to_text(self, value):
return '<a href="mailto:%s">%s</a>' % (value, value)
+
+# Network as used in routing configuration, such as
+# "10.0.0.0/8" or "192.168.56.1"
+class IPv4Network(TextAscii):
+ def __init__(self, **kwargs):
+ kwargs.setdefault("size", 12)
+ TextAscii.__init__(self, **kwargs)
+
+ def validate_value(self, value, varprefix):
+ if "/" in value:
+ try:
+ network, bits = value.split("/")
+ bits = int(bits)
+ except:
+ raise MKUserError(varprefix, _("Please use the syntax X.X.X.X/YY"))
+ else:
+ network = value
+ bits = 32
+
+ if bits < 0 or bits > 32:
+ raise MKUserError(varprefix, _("Invalid number of bits. Must be in range 1 ... 32"))
+
+ if value.count(".") != 3:
+ raise MKUserError(varprefix, _("The network must contain three dots"))
+ try:
+ octets = map(int, network.split("."))
+ if len(octets) != 4:
+ raise MKUserError(varprefix, _("Please specify four octets (X.X.X.X/YY)"))
+ for o in octets:
+ if o < 0 or o > 255:
+ raise MKUserError(varprefix, _("Invalid octet %d (must be in range 1 ... 255)") % o)
+ except MKUserError:
+ raise
+ except:
+ raise MKUserError(varprefix, _("Please use the syntax X.X.X.X/YY"))
+
+ # Make sure that non-network bits are zero
+ l = (octets[0] << 24) + (octets[1] << 16) + (octets[2] << 8) + (octets[3])
+ for b in range(bits, 32):
+ if l & (2 ** (31-b)) != 0:
+ raise MKUserError(varprefix, _("Please make sure that only the %d non-network bits are non-zero") % bits)
+
+
# Valuespec for a HTTP Url (not HTTPS), that
# automatically adds http:// to the value
class HTTPUrl(TextAscii):
Module: check_mk
Branch: master
Commit: 138fa4ef5e8706e1d4086fcf6478086223cfb08b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=138fa4ef5e8706…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Sat Mar 10 00:03:28 2012 +0100
WATO: bugfix, invisible folder attributes no longer lost on 'Save'
---
web/htdocs/wato.py | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 86629a5..b65adab 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -4043,30 +4043,28 @@ def configure_attributes(hosts, for_what, parent, myself=None, without_attribute
if attrname in without_attributes:
continue # e.g. needed to skip ipaddress in CSV-Import
- # Skip hidden attributes
+ # Hide invisible attributes
hide_attribute = False
- if not attr.show_in_form():
+ if for_what == "host" and not attr.show_in_form():
+ hide_attribute = True
+ elif (for_what == "folder" or for_what == "bulk") and not attr.show_in_folder():
hide_attribute = True
- # In folder not all attributes are shown
- if for_what == "folder" and not attr.show_in_folder():
- continue
-
- # Add host tag dependencies, but only in host mode. In other
- # modes we always need to show all attributes.
- if for_what == "host":
+ # Determine visibility information if this attribute is not always hidden
+ if not hide_attribute:
depends_on_tags = attr.depends_on_tags()
depends_on_roles = attr.depends_on_roles()
- if depends_on_tags:
+ # Add host tag dependencies, but only in host mode. In other
+ # modes we always need to show all attributes.
+ if for_what == "host" and depends_on_tags:
dependency_mapping_tags[attrname] = depends_on_tags
+
if depends_on_roles:
dependency_mapping_roles[attrname] = depends_on_roles
if not depends_on_tags and not depends_on_roles:
# One attribute is always shown -> topic is always visible
topic_is_volatile = False
- else:
- topic_is_volatile = False
# "bulk": determine, if this attribute has the same setting for all hosts.
values = []