summaryrefslogtreecommitdiff
path: root/addons/report_webkit/webkit_report.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@openerp.com>2014-03-24 14:38:11 +0100
committerChristophe Simonis <chs@openerp.com>2014-03-24 14:38:11 +0100
commitd93b79e6f4e5c6c2fda65fbf88df8e1851b6fa4d (patch)
treef855bc221056bf09cd4713d6cd44ab6b1449a268 /addons/report_webkit/webkit_report.py
parent7c4557add24726f34fec3aa834c34fa5c9b1f17f (diff)
parentf4b1d23cf2b44521456b479c1038e17d5ee0bac8 (diff)
[MERGE] forward port of branch saas-3 up to revid 9345 dle@openerp.com-20140324110349-e82t1bmmtjqbl85k
bzr revid: chs@openerp.com-20140324133811-4az1kvbznd26seow
Diffstat (limited to 'addons/report_webkit/webkit_report.py')
-rw-r--r--addons/report_webkit/webkit_report.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/addons/report_webkit/webkit_report.py b/addons/report_webkit/webkit_report.py
index 4f56d7efea7..60fb536ca96 100644
--- a/addons/report_webkit/webkit_report.py
+++ b/addons/report_webkit/webkit_report.py
@@ -112,6 +112,7 @@ def webkit_report_extender(report_name):
return fct
return fct1
+
class WebKitParser(report_sxw):
"""Custom class that use webkit to render HTML reports
Code partially taken from report openoffice. Thanks guys :)
@@ -173,7 +174,7 @@ class WebKitParser(report_sxw):
),
'w'
)
- head_file.write(header.encode('utf-8'))
+ head_file.write(self._sanitize_html(header.encode('utf-8')))
head_file.close()
file_to_del.append(head_file.name)
command.extend(['--header-html', head_file.name])
@@ -184,7 +185,7 @@ class WebKitParser(report_sxw):
),
'w'
)
- foot_file.write(footer.encode('utf-8'))
+ foot_file.write(self._sanitize_html(footer.encode('utf-8')))
foot_file.close()
file_to_del.append(foot_file.name)
command.extend(['--footer-html', foot_file.name])
@@ -205,7 +206,7 @@ class WebKitParser(report_sxw):
for html in html_list :
html_file = file(os.path.join(tmp_dir, str(time.time()) + str(count) +'.body.html'), 'w')
count += 1
- html_file.write(html.encode('utf-8'))
+ html_file.write(self._sanitize_html(html.encode('utf-8')))
html_file.close()
file_to_del.append(html_file.name)
command.append(html_file.name)
@@ -366,7 +367,6 @@ class WebKitParser(report_sxw):
pdf = self.generate_pdf(bin, report_xml, head, foot, htmls)
return (pdf, 'pdf')
-
def create(self, cursor, uid, ids, data, context=None):
"""We override the create function in order to handle generator
Code taken from report openoffice. Thanks guys :) """
@@ -387,11 +387,18 @@ class WebKitParser(report_sxw):
report_xml.report_sxw = None
else:
return super(WebKitParser, self).create(cursor, uid, ids, data, context)
- if report_xml.report_type != 'webkit' :
+ if report_xml.report_type != 'webkit':
return super(WebKitParser, self).create(cursor, uid, ids, data, context)
result = self.create_source_pdf(cursor, uid, ids, data, report_xml, context)
if not result:
return (False,False)
return result
+ def _sanitize_html(self, html):
+ """wkhtmltopdf expects the html page to declare a doctype.
+ """
+ if html and html[:9].upper() != "<!DOCTYPE":
+ html = "<!DOCTYPE html>\n" + html
+ return html
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: