Module: check_mk
Branch: master
Commit: e21b7e8b65d37eb9cc621f3d75ca784c538f70d9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e21b7e8b65d37e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Mar 21 10:25:26 2016 +0100
3313 FIX Set correct mime type when exporting CSV and other non-HTML formats
Conflicts:
.bugs/859
ChangeLog
---
.bugs/859 | 7 ++++---
.werks/3313 | 10 ++++++++++
ChangeLog | 1 +
web/htdocs/htmllib.py | 26 ++++++++++++++++++++++++++
web/htdocs/views.py | 1 -
web/htdocs/wato.py | 4 ++--
web/htdocs/webapi.py | 4 ++--
web/plugins/views/availability.py | 5 ++---
web/plugins/views/webservice.py | 1 -
9 files changed, 47 insertions(+), 12 deletions(-)
diff --git a/.bugs/859 b/.bugs/859
index e53241e..1cbe7a2 100644
--- a/.bugs/859
+++ b/.bugs/859
@@ -1,9 +1,10 @@
Title: Changing the output_format doesn't change the response header
Component: multisite
-State: open
+Class: bug
+State: done
Date: 2016-02-09 15:28:09
Targetversion: 1.2.8
Class: bug
+If you change the output_format for example to json, the response header is still html
-If you change the output_format for example to json, the mime type in the
-response header is still html.
+2016-03-21 09:59:59: changed state open -> done
diff --git a/.werks/3313 b/.werks/3313
new file mode 100644
index 0000000..e6ac239
--- /dev/null
+++ b/.werks/3313
@@ -0,0 +1,10 @@
+Title: Set correct mime type when exporting CSV and other non-HTML formats
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1458550901
+
+
diff --git a/ChangeLog b/ChangeLog
index 50cffd8..ba44d42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -115,6 +115,7 @@
* 3236 FIX: Fixed host page of pnp4nagios...
* 3293 FIX: Fixed graphs in IE with enabled compatibility mode (for IE < 8)
* 3294 FIX: Fixed mixed languages when some users have localized GUI and some not...
+ * 3313 FIX: Set correct mime type when exporting CSV and other non-HTML formats
WATO:
* 3244 WATO BI Module: swap order of aggregation function and child node
selection...
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index cf7fa88..a505076 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -170,8 +170,34 @@ class html(GUITester):
self.auto_id += 1
return "id_%d" % self.auto_id
+
def set_output_format(self, f):
self.output_format = f
+ if f == "json":
+ content_type = "application/json; charset=UTF-8"
+
+ elif f == "jsonp":
+ content_type = "application/javascript; charset=UTF-8"
+
+ elif f in ("csv", "csv_export"): # Cleanup: drop one of
these
+ content_type = "text/csv; charset=UTF-8"
+
+ elif f == "python":
+ content_type = "application/python; charset=UTF-8"
+
+ elif f == "text":
+ content_type = "text/plain; charset=UTF-8"
+
+ elif f == "html":
+ content_type = "text/html; charset=UTF-8"
+
+ elif f == "pdf":
+ content_type = "application/pdf"
+
+ else:
+ raise MKGeneralException(_("Unsupported context type '%s'")
% f)
+ self.set_content_type(content_type)
+
def set_link_target(self, framename):
self.link_target = framename
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index fc23571..d412f66 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -2503,7 +2503,6 @@ def ajax_inv_render_tree():
render_inv_subtree_container(hostname, tree_id, invpath, node)
def output_csv_headers(view):
- html.req.content_type = "text/csv; charset=UTF-8"
filename = '%s-%s.csv' % (view['name'],
time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(time.time())))
if type(filename) == unicode:
filename = filename.encode("utf-8")
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index c690c19..be6b91b 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -4736,7 +4736,7 @@ def render_audit_log(log, what, with_filename = False,
hilite_others=False):
html.write(htmlcode)
def export_audit_log():
- html.req.content_type = "text/csv; charset=UTF-8"
+ html.set_output_format("csv")
filename = 'wato-auditlog-%s_%s.csv' % (fmt_date(time.time()),
fmt_time(time.time()))
html.req.headers_out['Content-Disposition'] = 'attachment;
filename=%s' % filename
titles = (
@@ -13869,7 +13869,7 @@ def page_download_agent_output():
[host_name, ty])
if success:
- html.set_content_type("text/plain; charset=UTF-8")
+ html.set_output_format("text")
html.set_http_header("Content-Disposition", "Attachment;
filename=" + host_name)
html.write(agent_data)
else:
diff --git a/web/htdocs/webapi.py b/web/htdocs/webapi.py
index f2ab9ae..5b09b20 100644
--- a/web/htdocs/webapi.py
+++ b/web/htdocs/webapi.py
@@ -96,10 +96,10 @@ def page_api():
raise
response = { "result_code": 1, "result": str(e) }
- output_format = html.var("output_format", "json")
- if output_format == "json":
+ if html.output_format == "json":
html.write(json.dumps(response))
else:
+ html.set_output_format("python")
html.write(repr(response))
diff --git a/web/plugins/views/availability.py b/web/plugins/views/availability.py
index f6bf86d..88081b6 100644
--- a/web/plugins/views/availability.py
+++ b/web/plugins/views/availability.py
@@ -808,7 +808,7 @@ def output_availability_csv(what, av_data, avoptions):
for (title, help), (text, css) in zip(cell_titles, row_cells):
table.cell(title, text)
- av_output_csv_mimetype(_("Check_MK-Availability"))
+ av_output_set_content_disposition(_("Check_MK-Availability"))
availability_tables = availability.compute_availability_groups(what, av_data,
avoptions)
table.begin("av_items", output_format = "csv")
for group_title, availability_table in availability_tables:
@@ -825,8 +825,7 @@ def output_availability_csv(what, av_data, avoptions):
[(_("Summary"), "")] + [("",
"")] * pad, av_table["summary"])
table.end()
-def av_output_csv_mimetype(title):
- html.req.content_type = "text/csv; charset=UTF-8"
+def av_output_set_content_disposition(title):
filename = '%s-%s.csv' % (title, time.strftime('%Y-%m-%d_%H-%M-%S',
time.localtime(time.time())))
if type(filename) == unicode:
filename = filename.encode("utf-8")
diff --git a/web/plugins/views/webservice.py b/web/plugins/views/webservice.py
index e086b1f..888eef0 100644
--- a/web/plugins/views/webservice.py
+++ b/web/plugins/views/webservice.py
@@ -62,7 +62,6 @@ multisite_layouts["python"] = {
def render_json(rows, view, group_painters, painters, num_columns, show_checkboxes,
export=False):
if export:
- html.req.content_type = "appliation/json; charset=UTF-8"
filename = '%s-%s.json' % (view['name'],
time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(time.time())))
if type(filename) == unicode:
filename = filename.encode("utf-8")