You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Python source code encoding : https://www.python.org/dev/peps/pep-0263/
  3. ##############################################################################
  4. # For copyright and license notices, see __openerp__.py file in root directory
  5. ##############################################################################
  6. import urlparse
  7. import urllib
  8. from openerp import models
  9. from openerp.tools.translate import _
  10. class MailMail(models.Model):
  11. _inherit = 'mail.mail'
  12. def _get_unsubscribe_url(self, cr, uid, mail, email_to,
  13. msg=None, context=None):
  14. m_config = self.pool.get('ir.config_parameter')
  15. base_url = m_config.get_param(cr, uid, 'web.base.url')
  16. config_msg = m_config.get_param(cr, uid,
  17. 'mass_mailing.unsubscribe.label')
  18. url = urlparse.urljoin(
  19. base_url, 'mail/mailing/%(mailing_id)s/unsubscribe?%(params)s' % {
  20. 'mailing_id': mail.mailing_id.id,
  21. 'params': urllib.urlencode({
  22. 'db': cr.dbname,
  23. 'res_id': mail.res_id,
  24. 'email': email_to
  25. })
  26. }
  27. )
  28. html = ''
  29. if config_msg is False:
  30. html = '<small><a href="%(url)s">%(label)s</a></small>' % {
  31. 'url': url,
  32. 'label': msg or _('Click to unsubscribe'),
  33. }
  34. elif config_msg.lower() != 'false':
  35. html = config_msg % {
  36. 'url': url,
  37. }
  38. return html