summaryrefslogtreecommitdiff
path: root/addons/website_mail/models/email_template.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2014-03-03 11:40:44 +0100
committerThibault Delavallée <tde@openerp.com>2014-03-03 11:40:44 +0100
commit05fdc2290a2c8ef31f8a0df393cba29b196f6e37 (patch)
treec7a66a15a7d4c824ebb13bf34ae9f9f9ee2f7af7 /addons/website_mail/models/email_template.py
parenta9a4767d17650320cba710ce99b6c737419df7c7 (diff)
[IMP] email_template: relocate url rewritign stuff directly into the rendering method.
bzr revid: tde@openerp.com-20140303104044-hgmii31ga6msf72z
Diffstat (limited to 'addons/website_mail/models/email_template.py')
-rw-r--r--addons/website_mail/models/email_template.py50
1 files changed, 0 insertions, 50 deletions
diff --git a/addons/website_mail/models/email_template.py b/addons/website_mail/models/email_template.py
index 105fcff4428..beb02739f29 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,50 +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 generate_email_batch(self, cr, uid, template_id, res_ids, context=None, fields=None):
- """ Add a post processing after rendering, aka replace local URLs to absolute URLs. """
- results = super(EmailTemplate, self).generate_email_batch(cr, uid, template_id, res_ids, context=context, fields=fields)
- for res_id, value in results.iteritems():
- if 'body_html' in value:
- results[res_id]['body_html'] = self._postprocess_html_replace_links(cr, uid, value['body_html'], context=context)
- return results