summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2017-05-17 10:59:41 +0200
committerOlivier Dony <odo@openerp.com>2017-08-20 23:25:54 +0200
commit200612ca1ef1a1bf75dbe52feef5a09ae5a58ca6 (patch)
treec9243ec052649007c3c0c083b71cd290bc923f1a /addons
parentae866acf08abe91fe87a3d3f4899070962b795cc (diff)
[FIX] P3: text model in various mail bits
No formal decision there, and the stdlib API seems like a PITA as it's based around native strings, not bytes and not text. * try to use cross-model API instead of random encode/decode * unicode all the mail_template things * formataddr *requires* a text tuple now In P2, formataddr((False, False)) "worked" (generated "False <False>"), in P3 it will fail and blow up. * attachments are quite definitely bytes * remove try_coerce_ascii because it's garbage
Diffstat (limited to 'addons')
-rw-r--r--addons/mail/models/mail_mail.py2
-rw-r--r--addons/mail/models/mail_template.py10
-rw-r--r--addons/mail/tests/test_mail_features.py2
3 files changed, 7 insertions, 7 deletions
diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py
index 3f206424e07..e53c24fb176 100644
--- a/addons/mail/models/mail_mail.py
+++ b/addons/mail/models/mail_mail.py
@@ -169,7 +169,7 @@ class MailMail(models.Model):
- else fallback on mail.email_to splitting """
self.ensure_one()
if partner:
- email_to = [formataddr((partner.name, partner.email))]
+ email_to = [formataddr((partner.name or 'False', partner.email or 'False'))]
else:
email_to = tools.email_split_and_format(self.email_to)
return email_to
diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py
index e9bf605c382..f44ee7be09a 100644
--- a/addons/mail/models/mail_template.py
+++ b/addons/mail/models/mail_template.py
@@ -306,8 +306,8 @@ class MailTemplate(models.Model):
# 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)
+ 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)
@@ -324,12 +324,12 @@ class MailTemplate(models.Model):
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('data'):
+ 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')
+ 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('<div>') and html.endswith('</div>'):
+ if html.startswith(u'<div>') and html.endswith(u'</div>'):
html = html[5:-6]
return html
diff --git a/addons/mail/tests/test_mail_features.py b/addons/mail/tests/test_mail_features.py
index a6fce59c10a..8e2264ad6d3 100644
--- a/addons/mail/tests/test_mail_features.py
+++ b/addons/mail/tests/test_mail_features.py
@@ -131,7 +131,7 @@ class TestMessagePost(TestMail):
self.assertEqual(set(msg.attachment_ids.mapped('res_id')), set([self.test_pigs.id]),
'message_post: all atttachments should be linked to the pigs group')
self.assertEqual(set([base64.b64decode(x) for x in msg.attachment_ids.mapped('datas')]),
- set(['migration test', _attachments[0][1], _attachments[1][1]]))
+ set([b'migration test', _attachments[0][1], _attachments[1][1]]))
self.assertTrue(set([_attach_1.id, _attach_2.id]).issubset(msg.attachment_ids.ids),
'message_post: mail.message attachments duplicated')
# notifications