diff options
| author | Christophe Simonis <chs@openerp.com> | 2014-03-11 15:52:05 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@openerp.com> | 2014-03-11 15:52:05 +0100 |
| commit | d504764eff52354d4993863d72d1342bcdf704fb (patch) | |
| tree | 09b0d87666f8a8e56dad86d7bc53ea092551e0e2 /addons/website_mail/models | |
| parent | 96f744b2712fe0bd6f65ac93b4d347b1559123fc (diff) | |
| parent | 3ceefde48942df95000a0b89698ee71a1187fecb (diff) | |
[MERGE] forward port of branch saas-3 up to revid 9298 chm@openerp.com-20140311130852-3ft0v1mc9ht1any6
bzr revid: chs@openerp.com-20140311145205-s56fj113fsrnisc3
Diffstat (limited to 'addons/website_mail/models')
| -rw-r--r-- | addons/website_mail/models/email_template.py | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/addons/website_mail/models/email_template.py b/addons/website_mail/models/email_template.py index 6d84f91e5ab..87daac6aabb 100644 --- a/addons/website_mail/models/email_template.py +++ b/addons/website_mail/models/email_template.py @@ -19,9 +19,6 @@ # ############################################################################## -import lxml -import urlparse - from openerp.osv import osv, fields from openerp.tools.translate import _ @@ -39,52 +36,3 @@ class EmailTemplate(osv.Model): help='Link to the website', ), } - - def _postprocess_html_replace_links(self, cr, uid, body_html, context=None): - """ Post-processing of body_html. Indeed the content generated by the - website builder contains references to local addresses, for example - for images. This method changes those addresses to absolute addresses. """ - html = body_html - if not body_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 = '<div>%s</div>' % html - root = lxml.html.fromstring(html) - - base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url') - (base_scheme, base_netloc, bpath, bparams, bquery, bfragment) = urlparse.urlparse(base_url) - - def _process_link(url): - new_url = url - (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url) - if not scheme and not netloc: - new_url = urlparse.urlunparse((base_scheme, base_netloc, path, params, query, fragment)) - return new_url - - # check all nodes, replace : - # - img src -> check URL - # - a href -> check URL - for node in root.iter(): - if node.tag == 'a': - node.set('href', _process_link(node.get('href'))) - elif node.tag == 'img' and not node.get('src', 'data').startswith('data'): - node.set('src', _process_link(node.get('src'))) - - html = lxml.html.tostring(root, pretty_print=False, method='html') - # this is ugly, but lxml/etree tostring want to put everything in a 'div' that breaks the editor -> remove that - if html.startswith('<div>') and html.endswith('</div>'): - html = html[5:-6] - return html - - def create(self, cr, uid, values, context=None): - if 'body_html' in values: - values['body_html'] = self._postprocess_html_replace_links(cr, uid, values['body_html'], context=context) - return super(EmailTemplate, self).create(cr, uid, values, context=context) - - def write(self, cr, uid, ids, values, context=None): - if 'body_html' in values: - values['body_html'] = self._postprocess_html_replace_links(cr, uid, values['body_html'], context=context) - return super(EmailTemplate, self).write(cr, uid, ids, values, context=context) |
