From f62d35a403e1d6ae0f57206cea15512be3833b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Bernardi?= Date: Wed, 27 May 2020 10:14:01 -0300 Subject: [PATCH] lims_report_html: Report Template: parse stylesheets --- lims_report_html/results_report.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lims_report_html/results_report.py b/lims_report_html/results_report.py index 9d7abcf1..1daab39e 100644 --- a/lims_report_html/results_report.py +++ b/lims_report_html/results_report.py @@ -135,9 +135,11 @@ class ResultReport(metaclass=PoolMeta): content = cls.render_results_report_template(action, template_content, record=record, records=[record], data=data) + stylesheets = cls.parse_stylesheets(template_content) if action.extension == 'pdf': documents.append(PdfGenerator(content, side_margin=1, - extra_vertical_margin=30).render_html()) + extra_vertical_margin=30, + stylesheets=stylesheets).render_html()) else: documents.append(content) if action.extension == 'pdf': @@ -229,6 +231,20 @@ class ResultReport(metaclass=PoolMeta): b64_image = b64encode(image).decode() return 'data:image/png;base64,%s' % b64_image + @classmethod + def parse_stylesheets(cls, template_string): + Attachment = Pool().get('ir.attachment') + root = lxml_html.fromstring(template_string) + res = [] + # get stylesheets from attachments + elems = root.xpath("//div[@id='tryton_styles_container']/div") + for elem in elems: + css = Attachment.search([('id', '=', int(elem.attrib['id']))]) + if not css: + continue + res.append(css[0].data) + return res + class TemplateTranslations: