Browse Source

[IMP] mail_inline_css: allow passing options to premailer

pull/389/head
mpanarin 6 years ago
committed by Holger Brunn
parent
commit
740f136294
  1. 19
      mail_inline_css/models/mail_template.py

19
mail_inline_css/models/mail_template.py

@ -6,8 +6,8 @@
from odoo import api, models from odoo import api, models
try: try:
from premailer import transform
except (ImportError, IOError) as err:
from premailer import Premailer
except (ImportError, IOError) as err: # pragma: no cover
import logging import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
_logger.debug(err) _logger.debug(err)
@ -21,8 +21,19 @@ class MailTemplate(models.Model):
"""Use `premailer` to convert styles to inline styles.""" """Use `premailer` to convert styles to inline styles."""
result = super().generate_email(res_ids, fields=fields) result = super().generate_email(res_ids, fields=fields)
if isinstance(res_ids, int): 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: else:
for __, data in result.items(): 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 return result
def _get_premailer_options(self):
return {}
Loading…
Cancel
Save