cms.utils.mail: 21 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/cms/utils/mail.py

Stats: 0 executed, 15 missed, 6 excluded, 23 ignored

  1. # -*- coding: utf-8 -*-
  2. from django.core.mail import EmailMultiAlternatives
  3. from django.core.urlresolvers import reverse
  4. from django.template.loader import render_to_string
  5. from django.utils.translation import ugettext_lazy as _
  6. from django.contrib.sites.models import Site
  7. from cms.utils.urlutils import urljoin
  8. def send_mail(subject, txt_template, to, context=None, html_template=None, fail_silently=True):
  9. """
  10. Multipart message helper with template rendering.
  11. """
  12. site = Site.objects.get_current()
  13. context = context or {}
  14. context.update({
  15. 'login_url': "http://%s" % urljoin(site.domain, reverse('admin:index')),
  16. 'title': subject,
  17. })
  18. txt_body = render_to_string(txt_template, context)
  19. message = EmailMultiAlternatives(subject=subject, body=txt_body, to=to)
  20. if html_template:
  21. body = render_to_string(html_template, context)
  22. message.attach_alternative(body, 'text/html')
  23. message.send(fail_silently=fail_silently)
  24. def mail_page_user_change(user, created=False, password=""):
  25. """
  26. Send email notification to given user.
  27. Used it PageUser profile creation/update.
  28. """
  29. if created:
  30. subject = _('CMS - your user account was created.')
  31. else:
  32. subject = _('CMS - your user account was changed.')
  33. send_mail(subject, 'admin/cms/mail/page_user_change.txt', [user.email], {
  34. 'user': user,
  35. 'password': password or "*" * 8,
  36. 'created': created,
  37. }, 'admin/cms/mail/page_user_change.html')