regression in 1.5)
Message-ID: <5a730153.wZ6PcdAdhMpJSwNj%lm(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 30954cda18f844abd40f70b19e1dbd26880f24cc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=30954cda18f844…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jan 31 14:19:54 2018 +0100
5666 FIX Availability: Fixed broken editing of annotations (regression in 1.5)
Change-Id: Ia47704d643f4c1e3973a92be95041859b7e44d6e
---
.werks/5666 | 10 ++++
web/htdocs/forms.py | 6 +++
web/plugins/views/availability.py | 109 ++++++++++++++++++++++----------------
3 files changed, 78 insertions(+), 47 deletions(-)
diff --git a/.werks/5666 b/.werks/5666
new file mode 100644
index 0000000..8b64a21
--- /dev/null
+++ b/.werks/5666
@@ -0,0 +1,10 @@
+Title: Availability: Fixed broken editing of annotations (regression in 1.5)
+Level: 1
+Component: multisite
+Compatible: compat
+Edition: cre
+Version: 1.5.0i3
+Date: 1517404761
+Class: fix
+
+
diff --git a/web/htdocs/forms.py b/web/htdocs/forms.py
index 2c28273..cf9854c 100644
--- a/web/htdocs/forms.py
+++ b/web/htdocs/forms.py
@@ -41,6 +41,9 @@ def get_input(valuespec, varprefix):
return value
+# TODO: Remove all call sites and clean this up! The mechanic of this
+# and the edit_dictionaries() is very uncommon compared to the other
+# usages of valuespecs.
def edit_dictionary(entries, value, **args):
result = edit_dictionaries([("value", entries)], {"value":
value}, **args)
if result:
@@ -54,6 +57,9 @@ def edit_dictionary(entries, value, **args):
# TODO: As soon as the reports have been migrated to pagetypes.py
# we can drop edit_dictionaries()? At least the function for editing
# several dictionaries at once.
+# TODO: Remove all call sites and clean this up! The mechanic of this
+# and the edit_dictionary() is very uncommon compared to the other
+# usages of valuespecs.
def edit_dictionaries(dictionaries, value, focus=None, hover_help=True,
validate=None, buttontext=None, title=None,
buttons = None, method="GET", preview=False,
diff --git a/web/plugins/views/availability.py b/web/plugins/views/availability.py
index ef78c66..7bacc72 100644
--- a/web/plugins/views/availability.py
+++ b/web/plugins/views/availability.py
@@ -211,7 +211,6 @@ def render_availability_page(view, datasource, context, filterheaders,
only_site
html.write(confirmation_html_code)
# Remove variables for editing annotations, otherwise they will make it into the
uris
- html.del_all_vars("editanno_")
html.del_all_vars("anno_")
if html.var("filled_in") == "editanno":
html.del_var("filled_in")
@@ -744,7 +743,6 @@ def render_annotations(annotations, av_rawdata, what, avoptions,
omit_service):
table.end()
-
def edit_annotation():
site_id = html.var("anno_site") or ""
hostname = html.var("anno_host")
@@ -756,6 +754,7 @@ def edit_annotation():
# Find existing annotation with this specification
annotations = availability.load_annotations()
annotation = availability.find_annotation(annotations, site_host_svc, fromtime,
untiltime)
+
if not annotation:
value = {
"from" : fromtime,
@@ -764,59 +763,75 @@ def edit_annotation():
}
else:
value = annotation.copy()
+
value["host"] = hostname
value["service"] = service
value["site"] = site_id
- value = forms.edit_dictionary([
- ( "site", TextAscii(title = _("Site")) ),
- ( "host", TextUnicode(title = _("Hostname")) ),
- ( "service", Optional(TextUnicode(allow_empty=False), sameline = True,
title = _("Service")) ),
- ( "from", AbsoluteDate(title = _("Start-Time"),
include_time = True) ),
- ( "until", AbsoluteDate(title = _("End-Time"),
include_time = True) ),
- ( "downtime", Optional(
- DropdownChoice(
- choices = [
- ( True, _("regard as scheduled downtime")
),
- ( False, _("do not regard as scheduled
downtime") ),
- ],
- ),
- title = _("Scheduled downtime"),
- label = _("Reclassify downtime of this period"),
- )),
- ( "text", TextAreaUnicode(title = _("Annotation"),
allow_empty = False) ), ],
- value,
- varprefix = "editanno_",
- formname = "editanno",
- focus = "text")
-
- # FIXME: Is value not always given by the lines above??
- if value:
- site_host_svc = value["site"], value["host"],
value["service"]
- del value["site"]
- del value["host"]
- value["date"] = time.time()
- value["author"] = config.user.id
- availability.update_annotations(site_host_svc, value,
replace_existing=annotation)
- html.del_all_vars(prefix="editanno_")
- html.del_var("filled_in")
- return False
+ if html.check_transaction():
+ try:
+ vs = _vs_annotation()
+ value = vs.from_html_vars("_editanno")
+ vs.validate_value(value, "_editanno")
- else:
- title = _("Edit annotation of ") + hostname
- if service:
- title += "/" + service
+ site_host_svc = value["site"], value["host"],
value["service"]
+ del value["site"]
+ del value["host"]
+ value["date"] = time.time()
+ value["author"] = config.user.id
+ availability.update_annotations(site_host_svc, value,
replace_existing=annotation)
+ html.del_var("filled_in")
+ return False
+ except MKUserError, e:
+ html.user_error(e)
- html.body_start(title,
stylesheets=["pages","views","status"])
- html.top_heading(title)
+ title = _("Edit annotation of ") + hostname
+ if service:
+ title += "/" + service
- html.begin_context_buttons()
- html.context_button(_("Abort"), html.makeuri([("anno_host",
"")]), "abort")
- html.end_context_buttons()
+ html.body_start(title,
stylesheets=["pages","views","status"])
+ html.top_heading(title)
- html.bottom_footer()
- html.body_end()
- return True
+ html.begin_context_buttons()
+ html.context_button(_("Abort"), html.makeuri([("anno_host",
"")]), "abort")
+ html.end_context_buttons()
+
+ html.begin_form("editanno", method="GET")
+ _vs_annotation().render_input("_editanno", value, form=True)
+
+ html.button("save", _("Save"))
+
+ html.hidden_fields()
+ html.end_form()
+
+ html.bottom_footer()
+ html.body_end()
+ return True
+
+
+def _vs_annotation():
+ return Dictionary(
+ elements = [
+ ("site", TextAscii(title = _("Site")) ),
+ ("host", TextUnicode(title = _("Hostname")) ),
+ ("service", Optional(TextUnicode(allow_empty=False), sameline =
True, title = _("Service")) ),
+ ("from", AbsoluteDate(title = _("Start-Time"),
include_time = True) ),
+ ("until", AbsoluteDate(title = _("End-Time"),
include_time = True) ),
+ ("downtime", Optional(
+ DropdownChoice(
+ choices = [
+ ( True, _("regard as scheduled
downtime") ),
+ ( False, _("do not regard as scheduled
downtime") ),
+ ],
+ ),
+ title = _("Scheduled downtime"),
+ label = _("Reclassify downtime of this period"),
+ )),
+ ("text", TextAreaUnicode(title = _("Annotation"),
allow_empty = False) ),
+ ],
+ title = _("Edit annotation"),
+ optional_keys = [],
+ )
# Called at the beginning of every availability page