From 245e83d43b3775a64fd3fa5dc53344751f77aaf6 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Mon, 24 Mar 2014 11:17:31 +0100 Subject: [PATCH] [FIX] last version of wkhtmltopdf expects all file to have a doctype, inject one if not present bzr revid: sle@openerp.com-20140324101731-eqzqins3s8uak1yd --- addons/report_webkit/default_header.html | 1 + addons/report_webkit/webkit_report.py | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/report_webkit/default_header.html b/addons/report_webkit/default_header.html index 0798209a5b7..37fd4135b62 100644 --- a/addons/report_webkit/default_header.html +++ b/addons/report_webkit/default_header.html @@ -1,3 +1,4 @@ + diff --git a/addons/report_webkit/webkit_report.py b/addons/report_webkit/webkit_report.py index 56f361370f2..c6a30f5e579 100644 --- a/addons/report_webkit/webkit_report.py +++ b/addons/report_webkit/webkit_report.py @@ -61,6 +61,7 @@ def mako_template(text): tmp_lookup = TemplateLookup() #we need it in order to allow inclusion and inheritance return Template(text, input_encoding='utf-8', output_encoding='utf-8', lookup=tmp_lookup) + class WebKitParser(report_sxw): """Custom class that use webkit to render HTML reports Code partially taken from report openoffice. Thanks guys :) @@ -122,7 +123,7 @@ class WebKitParser(report_sxw): ), 'w' ) - head_file.write(header) + head_file.write(self._sanitize_html(header)) head_file.close() file_to_del.append(head_file.name) command.extend(['--header-html', head_file.name]) @@ -133,7 +134,7 @@ class WebKitParser(report_sxw): ), 'w' ) - foot_file.write(footer) + foot_file.write(self._sanitize_html(footer)) foot_file.close() file_to_del.append(foot_file.name) command.extend(['--footer-html', foot_file.name]) @@ -154,7 +155,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) + html_file.write(self._sanitize_html(html)) html_file.close() file_to_del.append(html_file.name) command.append(html_file.name) @@ -314,7 +315,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 :) """ @@ -335,11 +335,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() != "\n" + html + return html + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: