Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix bug 852214: Add support for multipart text and html emails.

  • Loading branch information...
commit 47d849b271a5c622b9bc6ef4c19c423b9450ad6b 1 parent 7349907
Michael Kelly authored March 18, 2013
12  flicks/base/templates/email_base.ltxt
... ...
@@ -0,0 +1,12 @@
  1
+{# L10n: Greeting in an email. #}
  2
+{%- trans name=user.profile.display_name %}
  3
+  Hi {{ name }},
  4
+{% endtrans %}
  5
+
  6
+
  7
+{% block message %}{% endblock %}
  8
+
  9
+{# L10n: Part of the signature on an email. -#}
  10
+{{ _('Sincerely,') }}
  11
+{# L10n: Part of the signature on an email. -#}
  12
+{{ _('The Firefox Flicks Team') }}
17  flicks/settings/base.py
@@ -70,23 +70,12 @@
70 70
         ('**/flicks/**.py',
71 71
             'tower.management.commands.extract.extract_tower_python'),
72 72
         ('**/flicks/**/templates/**.html',
73  
-            'tower.management.commands.extract.extract_tower_template')
  73
+            'tower.management.commands.extract.extract_tower_template'),
  74
+        ('**/flicks/**/templates/**.ltxt',
  75
+            'tower.management.commands.extract.extract_tower_template'),
74 76
     ],
75 77
 }
76 78
 
77  
-# # Use this if you have localizable HTML files:
78  
-# DOMAIN_METHODS['lhtml'] = [
79  
-#    ('**/templates/**.lhtml',
80  
-#        'tower.management.commands.extract.extract_tower_template'),
81  
-# ]
82  
-
83  
-# # Use this if you have localizable HTML files:
84  
-# DOMAIN_METHODS['javascript'] = [
85  
-#    # Make sure that this won't pull in strings from external libraries you
86  
-#    # may use.
87  
-#    ('media/js/**.js', 'javascript'),
88  
-# ]
89  
-
90 79
 # Always generate a CSRF token for anonymous users
91 80
 ANON_ALWAYS = True
92 81
 
16  flicks/videos/templates/videos/2013/approval_email.ltxt
... ...
@@ -0,0 +1,16 @@
  1
+{% extends 'email_base.ltxt' %}
  2
+
  3
+{% block message %}
  4
+{{ _('Your flick has been accepted and successfully added to the competition!') }}
  5
+
  6
+{# HACK: Add the user's locale as a urlparam to force a redirect to the correct locale. -#}
  7
+{% set details_link = absolutify(url('flicks.videos.detail', video.id))|urlparams(lang=user.profile.locale) -%}
  8
+{% trans link=details_link %}
  9
+  You can find your flick on the gallery and share it using this link: {{ link }}
  10
+{% endtrans %}
  11
+
  12
+
  13
+{{ _('Voting for the People\'s Choice Award starts on July 31, so be sure to let your friends know that you need their support.') }}
  14
+
  15
+{{ _('Thanks again for taking the time to help us share the power of mobile with the world.') }}
  16
+{% endblock %}
12  flicks/videos/templates/videos/2013/rejection_email.ltxt
... ...
@@ -0,0 +1,12 @@
  1
+{% extends 'email_base.ltxt' %}
  2
+
  3
+{% block message %}
  4
+{# HACK: Add the user's locale as a urlparam to force a redirect to the correct locale. -#}
  5
+{% trans link=absolutify(url('flicks.base.rules'))|urlparams(lang=user.profile.locale) %}
  6
+  Unfortunately, your flick does not meet one or more of the contest criteria and was not accepted to be part of the competition. Please refer to our contest rules for more information: {{ link }}
  7
+{% endtrans %}
  8
+
  9
+
  10
+{{ _('All decisions regarding submissions are final.') }}
  11
+{% endblock %}
  12
+
24  flicks/videos/util.py
... ...
@@ -1,7 +1,7 @@
1 1
 from urllib import urlencode
2 2
 
3 3
 from django.conf import settings
4  
-from django.core.mail import EmailMessage
  4
+from django.core.mail import EmailMultiAlternatives
5 5
 from django.contrib.auth.models import User
6 6
 from django.template.loader import render_to_string
7 7
 
@@ -53,11 +53,15 @@ def send_approval_email(video):
53 53
     """
54 54
     profile = video.user.profile
55 55
     with use_lang(profile.locale if profile else settings.LANGUAGE_CODE):
56  
-        body = render_to_string('videos/2013/approval_email.html', {
  56
+        text_body = render_to_string('videos/2013/approval_email.ltxt', {
57 57
             'user': video.user,
58 58
             'video': video
59 59
         })
60  
-    _send_mail(EMAIL_SUBJECT, body, [video.user.email])
  60
+        html_body = render_to_string('videos/2013/approval_email.html', {
  61
+            'user': video.user,
  62
+            'video': video
  63
+        })
  64
+    _send_mail(EMAIL_SUBJECT, text_body, html_body, [video.user.email])
61 65
 
62 66
 
63 67
 def send_rejection_email(user_id):
@@ -68,13 +72,17 @@ def send_rejection_email(user_id):
68 72
     user = get_object_or_none(User, id=user_id)
69 73
     if user:
70 74
         with use_lang(user.profile.locale):
71  
-            body = render_to_string('videos/2013/rejection_email.html', {
  75
+            text_body = render_to_string('videos/2013/rejection_email.ltxt', {
  76
+                'user': user
  77
+            })
  78
+            html_body = render_to_string('videos/2013/rejection_email.html', {
72 79
                 'user': user
73 80
             })
74  
-        _send_mail(EMAIL_SUBJECT, body, [user.email])
  81
+        _send_mail(EMAIL_SUBJECT, text_body, html_body, [user.email])
75 82
 
76 83
 
77  
-def _send_mail(subject, body, recipients):
78  
-    msg = EmailMessage(subject, body, settings.DEFAULT_FROM_EMAIL, recipients)
79  
-    msg.content_subtype = 'html'
  84
+def _send_mail(subject, text_body, html_body, recipients):
  85
+    msg = EmailMultiAlternatives(subject, text_body,
  86
+                                 settings.DEFAULT_FROM_EMAIL, recipients)
  87
+    msg.attach_alternative(html_body, 'text/html')
80 88
     msg.send()

0 notes on commit 47d849b

Please sign in to comment.
Something went wrong with that request. Please try again.