[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:
parent
3dc2fcd363
commit
66969f51fa
|
@ -211,21 +211,22 @@ class Report(osv.Model):
|
||||||
# in order to extract headers, bodies and footers.
|
# in order to extract headers, bodies and footers.
|
||||||
try:
|
try:
|
||||||
root = lxml.html.fromstring(html)
|
root = lxml.html.fromstring(html)
|
||||||
|
match_klass = "//div[contains(concat(' ', normalize-space(@class), ' '), ' {} ')]"
|
||||||
|
|
||||||
for node in root.xpath("//html/head/style"):
|
for node in root.xpath("//html/head/style"):
|
||||||
css += node.text
|
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)
|
body = lxml.html.tostring(node)
|
||||||
header = render_minimal(dict(css=css, subst=True, body=body, base_url=base_url))
|
header = render_minimal(dict(css=css, subst=True, body=body, base_url=base_url))
|
||||||
headerhtml.append(header)
|
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)
|
body = lxml.html.tostring(node)
|
||||||
footer = render_minimal(dict(css=css, subst=True, body=body, base_url=base_url))
|
footer = render_minimal(dict(css=css, subst=True, body=body, base_url=base_url))
|
||||||
footerhtml.append(footer)
|
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
|
# 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
|
# 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
|
# branding in order to do so: searching after a node having a data-oe-model
|
||||||
|
|
Loading…
Reference in New Issue