import cStringIO
import subprocess
from distutils.version import LooseVersion
-try:
- from pyPdf import PdfFileWriter, PdfFileReader
-except ImportError:
- PdfFileWriter = PdfFileReader = None
+from functools import partial
+from pyPdf import PdfFileWriter, PdfFileReader
_logger = logging.getLogger(__name__)
public_user = None
- MINIMAL_HTML_PAGE = """
-<base href="{base_url}">
-<!DOCTYPE html>
-<html style="height: 0;">
- <head>
- <link href="/report/static/src/css/reset.min.css" rel="stylesheet"/>
- <link href="/web/static/lib/bootstrap/css/bootstrap.css" rel="stylesheet"/>
- <link href="/website/static/src/css/website.css" rel="stylesheet"/>
- <link href="/web/static/lib/fontawesome/css/font-awesome.css" rel="stylesheet"/>
- <style type='text/css'>{css}</style>
- {subst}
- </head>
- <body class="container" onload="subst()">
- {body}
- </body>
-</html>"""
-
#--------------------------------------------------------------------------
# Extension of ir_ui_view.render with arguments frequently used in reports
#--------------------------------------------------------------------------
footerhtml = []
base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url')
+ # Minimal page renderer
+ view_obj = self.pool['ir.ui.view']
+ render_minimal = partial(view_obj.render, cr, uid, 'report.minimal_layout', context=context)
+
+
# The received html report must be simplified. We convert it in a xml tree
# in order to extract headers, bodies and footers.
try:
for node in root.xpath("//div[@class='header']"):
body = lxml.html.tostring(node)
- header = self.MINIMAL_HTML_PAGE.format(css=css, subst=subst, body=body, base_url=base_url)
+ header = render_minimal(dict(css=css, subst=subst, body=body, base_url=base_url))
headerhtml.append(header)
for node in root.xpath("//div[@class='footer']"):
body = lxml.html.tostring(node)
- footer = self.MINIMAL_HTML_PAGE.format(css=css, subst=subst, body=body, base_url=base_url)
+ footer = render_minimal(dict(css=css, subst=subst, body=body, base_url=base_url))
footerhtml.append(footer)
for node in root.xpath("//div[@class='page']"):
reportid = False
body = lxml.html.tostring(node)
- reportcontent = self.MINIMAL_HTML_PAGE.format(css=css, subst='', body=body, base_url=base_url)
+ reportcontent = render_minimal(dict(css=css, subst='', body=body, base_url=base_url))
# FIXME: imo the best way to extract record id from html reports is by using the
# qweb branding. As website editor is not yet splitted in a module independant from