[FIX] Report: get_pdf: don't miss main elements when parsing html

Main elements can have more than one class, thus can be ignored by the previous
naive xpath. This patch brings a stronger xpath.
This commit is contained in:
Simone Orsi 2014-11-05 11:47:10 +01:00 committed by Simon Lejeune
parent 3dc2fcd363
commit 66969f51fa
1 changed files with 4 additions and 3 deletions

View File

@ -211,21 +211,22 @@ class Report(osv.Model):
# in order to extract headers, bodies and footers.
try:
root = lxml.html.fromstring(html)
match_klass = "//div[contains(concat(' ', normalize-space(@class), ' '), ' {} ')]"
for node in root.xpath("//html/head/style"):
css += node.text
for node in root.xpath("//div[@class='header']"):
for node in root.xpath(match_klass.format('header')):
body = lxml.html.tostring(node)
header = render_minimal(dict(css=css, subst=True, body=body, base_url=base_url))
headerhtml.append(header)
for node in root.xpath("//div[@class='footer']"):
for node in root.xpath(match_klass.format('footer')):
body = lxml.html.tostring(node)
footer = render_minimal(dict(css=css, subst=True, body=body, base_url=base_url))
footerhtml.append(footer)
for node in root.xpath("//div[@class='page']"):
for node in root.xpath(match_klass.format('page')):
# Previously, we marked some reports to be saved in attachment via their ids, so we
# must set a relation between report ids and report's content. We use the QWeb
# branding in order to do so: searching after a node having a data-oe-model