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 :)
),
'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])
),
'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])
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)
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 :) """
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: