From 740f1362942f7591b16dcd6b1ff735990f77aec1 Mon Sep 17 00:00:00 2001 From: mpanarin Date: Fri, 18 Jan 2019 12:48:07 +0200 Subject: [PATCH] [IMP] mail_inline_css: allow passing options to premailer --- mail_inline_css/models/mail_template.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mail_inline_css/models/mail_template.py b/mail_inline_css/models/mail_template.py index 9bb40311..647fbdf7 100644 --- a/mail_inline_css/models/mail_template.py +++ b/mail_inline_css/models/mail_template.py @@ -6,8 +6,8 @@ from odoo import api, models try: - from premailer import transform -except (ImportError, IOError) as err: + from premailer import Premailer +except (ImportError, IOError) as err: # pragma: no cover import logging _logger = logging.getLogger(__name__) _logger.debug(err) @@ -21,8 +21,19 @@ class MailTemplate(models.Model): """Use `premailer` to convert styles to inline styles.""" result = super().generate_email(res_ids, fields=fields) if isinstance(res_ids, int): - result['body_html'] = transform(result['body_html']) + premailer = Premailer( + html=result['body_html'], + **self._get_premailer_options(), + ) + result['body_html'] = premailer.transform() else: for __, data in result.items(): - data['body_html'] = transform(data['body_html']) + premailer = Premailer( + html=data['body_html'], + **self._get_premailer_options(), + ) + data['body_html'] = premailer.transform() return result + + def _get_premailer_options(self): + return {}