diff options
Diffstat (limited to 'addons/report_webkit')
| -rw-r--r-- | addons/report_webkit/default_header.html | 1 | ||||
| -rw-r--r-- | 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 @@ +<!DOCTYPE html> <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="content-type"/> 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: |
