Module: check_mk
Branch: master
Commit: 7b22ff140c302434112a09a48437b5180f1af1ef
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7b22ff140c3024…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Mar 22 15:14:19 2016 +0100
3318 FIX CSV bulk import of hosts: fix handling of CSV column headers
Reenable the feature of automatic detection of the correct column. Remove
bogus {{None}} headers if headers are disabled.
---
.werks/3318 | 11 +++++++++++
ChangeLog | 1 +
web/htdocs/wato.py | 22 +++++++++++++++-------
3 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/.werks/3318 b/.werks/3318
new file mode 100644
index 0000000..bfdda06
--- /dev/null
+++ b/.werks/3318
@@ -0,0 +1,11 @@
+Title: CSV bulk import of hosts: fix handling of CSV column headers
+Level: 1
+Component: wato
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1458656003
+
+Reenable the feature of automatic detection of the correct column. Remove
+bogus {{None}} headers if headers are disabled.
diff --git a/ChangeLog b/ChangeLog
index 6fb8537..a2bb2bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -171,6 +171,7 @@
* 3316 FIX: Fix validation of empty or missing file uploads (such as in Bulk host
import)
* 3302 FIX: Improved error handling when trying to edit a not existing rule
* 3338 FIX: Improved error handling when host to be edited does not exist
+ * 3318 FIX: CSV bulk import of hosts: fix handling of CSV column headers...
Notifications:
* 3263 Notifications: allow users to restrict by their contact groups...
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 61df313..cf18b05 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -2964,6 +2964,8 @@ class ModeBulkImport(WatoMode):
def buttons(self):
html.context_button(_("Abort"),
folder_preserving_link([("mode", "folder")]), "abort")
+ if html.has_var("file_id"):
+ html.context_button(_("Back"),
folder_preserving_link([("mode", "bulk_import")]), "back")
def action(self):
@@ -3112,7 +3114,7 @@ class ModeBulkImport(WatoMode):
raise MKUserError(None, _("Invalid host name: %r. Only the
characters a-z, A-Z, "
"0-9, _, . and - are allowed.") %
value)
host_name = value
- elif attribute:
+ elif attribute and attribute != "-":
if attribute in attributes:
raise MKUserError(None, _("The attribute \"%s\" is
assigned to multiple columns. "
"You can not populate one attribute
from multiple columns. "
@@ -3149,7 +3151,6 @@ class ModeBulkImport(WatoMode):
html.end_form()
-
def _vs_upload(self):
return Dictionary(
elements = [
@@ -3210,15 +3211,21 @@ class ModeBulkImport(WatoMode):
# Determine how many columns should be rendered by using the longest column
num_columns = max([ len(r) for r in [headers] + rows ])
- table.begin(sortable=False, searchable=False)
+ table.begin(sortable=False, searchable=False, omit_headers = not
self._params.get("has_title_line"))
# Render attribute selection fields
table.row()
for col_num in range(num_columns):
header = len(headers) > col_num and headers[col_num] or None
table.cell(html.attrencode(header))
- html.select("attribute_%d" % col_num, attributes,
self._try_detect_default_attribute(attributes, header),
- attrs={"autocomplete": "off"})
+ attribute_varname = "attribute_%d" % col_num
+ if html.var(attribute_varname):
+ attribute_method = html.var("attribute_varname")
+ else:
+ attribute_method = self._try_detect_default_attribute(attributes,
header)
+ html.del_var(attribute_varname)
+
+ html.select("attribute_%d" % col_num, attributes, attribute_method,
attrs={"autocomplete": "off"})
# Render sample rows
for row in rows:
@@ -3263,7 +3270,8 @@ class ModeBulkImport(WatoMode):
def _attribute_choices(self):
attributes = [
- (None, _("Don't import")),
+ (None, _("(please select)")),
+ ("-", _("Don't import")),
("host_name", _("Hostname")),
("alias", _("Alias")),
("ipaddress", _("IPv4 Address")),
@@ -3273,7 +3281,7 @@ class ModeBulkImport(WatoMode):
# Add tag groups
for entry in configured_host_tags():
- attributes.append(("tag_"+entry[0], _("Tag: %s") %
entry[1]))
+ attributes.append(("tag_" + entry[0], _("Tag: %s") %
entry[1]))
return attributes