[FIX] last version of wkhtmltopdf expects all file to have a doctype, inject one if not present
bzr revid: sle@openerp.com-20140324101731-eqzqins3s8uak1yd
This commit is contained in:
parent
6472e4155a
commit
245e83d43b
|
@ -1,3 +1,4 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
|
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
|
||||||
|
|
|
@ -61,6 +61,7 @@ def mako_template(text):
|
||||||
tmp_lookup = TemplateLookup() #we need it in order to allow inclusion and inheritance
|
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)
|
return Template(text, input_encoding='utf-8', output_encoding='utf-8', lookup=tmp_lookup)
|
||||||
|
|
||||||
|
|
||||||
class WebKitParser(report_sxw):
|
class WebKitParser(report_sxw):
|
||||||
"""Custom class that use webkit to render HTML reports
|
"""Custom class that use webkit to render HTML reports
|
||||||
Code partially taken from report openoffice. Thanks guys :)
|
Code partially taken from report openoffice. Thanks guys :)
|
||||||
|
@ -122,7 +123,7 @@ class WebKitParser(report_sxw):
|
||||||
),
|
),
|
||||||
'w'
|
'w'
|
||||||
)
|
)
|
||||||
head_file.write(header)
|
head_file.write(self._sanitize_html(header))
|
||||||
head_file.close()
|
head_file.close()
|
||||||
file_to_del.append(head_file.name)
|
file_to_del.append(head_file.name)
|
||||||
command.extend(['--header-html', head_file.name])
|
command.extend(['--header-html', head_file.name])
|
||||||
|
@ -133,7 +134,7 @@ class WebKitParser(report_sxw):
|
||||||
),
|
),
|
||||||
'w'
|
'w'
|
||||||
)
|
)
|
||||||
foot_file.write(footer)
|
foot_file.write(self._sanitize_html(footer))
|
||||||
foot_file.close()
|
foot_file.close()
|
||||||
file_to_del.append(foot_file.name)
|
file_to_del.append(foot_file.name)
|
||||||
command.extend(['--footer-html', foot_file.name])
|
command.extend(['--footer-html', foot_file.name])
|
||||||
|
@ -154,7 +155,7 @@ class WebKitParser(report_sxw):
|
||||||
for html in html_list :
|
for html in html_list :
|
||||||
html_file = file(os.path.join(tmp_dir, str(time.time()) + str(count) +'.body.html'), 'w')
|
html_file = file(os.path.join(tmp_dir, str(time.time()) + str(count) +'.body.html'), 'w')
|
||||||
count += 1
|
count += 1
|
||||||
html_file.write(html)
|
html_file.write(self._sanitize_html(html))
|
||||||
html_file.close()
|
html_file.close()
|
||||||
file_to_del.append(html_file.name)
|
file_to_del.append(html_file.name)
|
||||||
command.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)
|
pdf = self.generate_pdf(bin, report_xml, head, foot, htmls)
|
||||||
return (pdf, 'pdf')
|
return (pdf, 'pdf')
|
||||||
|
|
||||||
|
|
||||||
def create(self, cursor, uid, ids, data, context=None):
|
def create(self, cursor, uid, ids, data, context=None):
|
||||||
"""We override the create function in order to handle generator
|
"""We override the create function in order to handle generator
|
||||||
Code taken from report openoffice. Thanks guys :) """
|
Code taken from report openoffice. Thanks guys :) """
|
||||||
|
@ -335,11 +335,18 @@ class WebKitParser(report_sxw):
|
||||||
report_xml.report_sxw = None
|
report_xml.report_sxw = None
|
||||||
else:
|
else:
|
||||||
return super(WebKitParser, self).create(cursor, uid, ids, data, context)
|
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)
|
return super(WebKitParser, self).create(cursor, uid, ids, data, context)
|
||||||
result = self.create_source_pdf(cursor, uid, ids, data, report_xml, context)
|
result = self.create_source_pdf(cursor, uid, ids, data, report_xml, context)
|
||||||
if not result:
|
if not result:
|
||||||
return (False,False)
|
return (False,False)
|
||||||
return result
|
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:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
Loading…
Reference in New Issue