diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-02-12 18:34:43 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-02-12 18:34:43 +0100 |
| commit | adeea2a88db4443b2b426877a28bb1471c2f5db1 (patch) | |
| tree | 2f43fecc9649947d3061e8c482219fa167b3385a /addons/mail/models/mail_template.py | |
| parent | 317f5f11112266128ac2292ecfafcd92cda74fd0 (diff) | |
| parent | 0f02dcb63918228d48df50f2d5805b7fda25c14a (diff) | |
[MERGE] forward port branch saas-11.2 up to 0f02dcb6391
Diffstat (limited to 'addons/mail/models/mail_template.py')
| -rw-r--r-- | addons/mail/models/mail_template.py | 39 |
1 files changed, 1 insertions, 38 deletions
diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index 2407e58fdbd..17cea52deac 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -315,45 +315,8 @@ class MailTemplate(models.Model): # ---------------------------------------- @api.model - def _replace_local_links(self, html): - """ Post-processing of html content to replace local links to absolute - links, using web.base.url as base url. """ - if not html: - return html - - # form a tree - root = lxml.html.fromstring(html) - if not len(root) and root.text is None and root.tail is None: - html = u'<div>%s</div>' % html - root = lxml.html.fromstring(html, encoding='unicode') - - base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') - base = urls.url_parse(base_url) - - def _process_link(url): - new_url = urls.url_parse(url) - if new_url.scheme and (new_url.netloc or new_url.scheme == 'mailto'): - return url - return new_url.replace(scheme=base.scheme, netloc=base.netloc).to_url() - - # check all nodes, replace : - # - img src -> check URL - # - a href -> check URL - for node in root.iter(): - if node.tag == 'a' and node.get('href'): - node.set('href', _process_link(node.get('href'))) - elif node.tag == 'img' and not node.get('src', 'data').startswith(u'data'): - node.set('src', _process_link(node.get('src'))) - - html = lxml.html.tostring(root, pretty_print=False, method='html', encoding='unicode') - # this is ugly, but lxml/etree tostring want to put everything in a 'div' that breaks the editor -> remove that - if html.startswith(u'<div>') and html.endswith(u'</div>'): - html = html[5:-6] - return html - - @api.model def render_post_process(self, html): - html = self._replace_local_links(html) + html = self.env['mail.thread']._replace_local_links(html) return html @api.model |
