diff options
| author | std-odoo <std@odoo.com> | 2020-08-10 08:07:48 +0000 |
|---|---|---|
| committer | std-odoo <std@odoo.com> | 2020-08-18 08:47:28 +0000 |
| commit | 13d1f3e012d0c528dbea67ee5e1d4c32548195a3 (patch) | |
| tree | eb69f43e611d962243163b03dc48a06ce0885cb2 /addons/mail/models/mail_render_mixin.py | |
| parent | 8d62eacfff5f94f692661c221c7b43f39bd3b891 (diff) | |
[IMP] mass_mailing: allow to customize the mail preview
Purpose
=======
Allow to customize the preview text in mass mailing.
Specifications
==============
We do not generate the preview text anymore, instead we add
a new field to let the user choose want he want to put into
the preview. As the preview is added in the mail body, it
supports dynamic placeholders.
Rename "View in browser" into "View Online" because the text
will be displayed in the preview if the snippet is added at
the beginning of the email. And we want to make it shorter.
Remove the alt attribute of the image tag which are not part
of the "email content" in the mass mailing template.
So, we improve the email preview in the mail clients
(otherwise the mail client include the alt attribute into the
preview).
Task-2313872
closes odoo/odoo#55695
Related: odoo/upgrade#1584
Related: odoo/enterprise#12323
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/mail/models/mail_render_mixin.py')
| -rw-r--r-- | addons/mail/models/mail_render_mixin.py | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/addons/mail/models/mail_render_mixin.py b/addons/mail/models/mail_render_mixin.py index db29d266114..d35fbf5dddf 100644 --- a/addons/mail/models/mail_render_mixin.py +++ b/addons/mail/models/mail_render_mixin.py @@ -207,45 +207,26 @@ class MailRenderMixin(models.AbstractModel): return html @api.model - def _generate_preview(self, html): - """ Generate a preview of html, to used for example in marketing emails. - - We add the character `‌` (zero-width non-joiner) to fill the end of - the preview in order to not have the beginning of the mail at the end of - the preview (don't work with simple space as the content is trimmed). - https://litmus.com/blog/the-ultimate-guide-to-preview-text-support - - :param html: html content for which we generate the preview - :return: html to use as preview - """ - preview = "" - for element in re.finditer(r"\>([^<>]+)\<", html): - element = element.group(1).strip() - if element: - preview += " %s" % element - if len(preview) > 500: - break - - html_preview = f""" - <div style="display:none;font-size:1px;height:0px;width:0px;opacity:0;"> - {tools.html_escape(preview)} {'‌ ' * 500} - </div> - """ if preview else '' - - return html_preview - - @api.model - def _prepend_preview(self, html): + def _prepend_preview(self, html, preview): """ Prepare the email body before sending. Add the text preview at the beginning of the mail. The preview text is displayed bellow the mail subject of most mail client (gmail, outlook...). - See ``_generate_preview()`` for more details about the preview computation. - :param html: html content for which we want to prepend a preview + :param preview: the preview to add before the html content :return: html with preprended preview """ - return tools.prepend_html_content(html, self._generate_preview(html)) + if preview: + preview = preview.strip() + + if preview: + html_preview = f""" + <div style="display:none;font-size:1px;height:0px;width:0px;opacity:0;"> + {tools.html_escape(preview)} + </div> + """ + return tools.prepend_html_content(html, html_preview) + return html # ------------------------------------------------------------ # RENDERING |
