Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 47d849b271a5c622b9bc6ef4c19c423b9450ad6b 1 parent 7349907
@Osmose Osmose authored
View
12 flicks/base/templates/email_base.ltxt
@@ -0,0 +1,12 @@
+{# L10n: Greeting in an email. #}
+{%- trans name=user.profile.display_name %}
+ Hi {{ name }},
+{% endtrans %}
+
+
+{% block message %}{% endblock %}
+
+{# L10n: Part of the signature on an email. -#}
+{{ _('Sincerely,') }}
+{# L10n: Part of the signature on an email. -#}
+{{ _('The Firefox Flicks Team') }}
View
17 flicks/settings/base.py
@@ -70,23 +70,12 @@
('**/flicks/**.py',
'tower.management.commands.extract.extract_tower_python'),
('**/flicks/**/templates/**.html',
- 'tower.management.commands.extract.extract_tower_template')
+ 'tower.management.commands.extract.extract_tower_template'),
+ ('**/flicks/**/templates/**.ltxt',
+ 'tower.management.commands.extract.extract_tower_template'),
],
}
-# # Use this if you have localizable HTML files:
-# DOMAIN_METHODS['lhtml'] = [
-# ('**/templates/**.lhtml',
-# 'tower.management.commands.extract.extract_tower_template'),
-# ]
-
-# # Use this if you have localizable HTML files:
-# DOMAIN_METHODS['javascript'] = [
-# # Make sure that this won't pull in strings from external libraries you
-# # may use.
-# ('media/js/**.js', 'javascript'),
-# ]
-
# Always generate a CSRF token for anonymous users
ANON_ALWAYS = True
View
16 flicks/videos/templates/videos/2013/approval_email.ltxt
@@ -0,0 +1,16 @@
+{% extends 'email_base.ltxt' %}
+
+{% block message %}
+{{ _('Your flick has been accepted and successfully added to the competition!') }}
+
+{# HACK: Add the user's locale as a urlparam to force a redirect to the correct locale. -#}
+{% set details_link = absolutify(url('flicks.videos.detail', video.id))|urlparams(lang=user.profile.locale) -%}
+{% trans link=details_link %}
+ You can find your flick on the gallery and share it using this link: {{ link }}
+{% endtrans %}
+
+
+{{ _('Voting for the People\'s Choice Award starts on July 31, so be sure to let your friends know that you need their support.') }}
+
+{{ _('Thanks again for taking the time to help us share the power of mobile with the world.') }}
+{% endblock %}
View
12 flicks/videos/templates/videos/2013/rejection_email.ltxt
@@ -0,0 +1,12 @@
+{% extends 'email_base.ltxt' %}
+
+{% block message %}
+{# HACK: Add the user's locale as a urlparam to force a redirect to the correct locale. -#}
+{% trans link=absolutify(url('flicks.base.rules'))|urlparams(lang=user.profile.locale) %}
+ 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 }}
+{% endtrans %}
+
+
+{{ _('All decisions regarding submissions are final.') }}
+{% endblock %}
+
View
24 flicks/videos/util.py
@@ -1,7 +1,7 @@
from urllib import urlencode
from django.conf import settings
-from django.core.mail import EmailMessage
+from django.core.mail import EmailMultiAlternatives
from django.contrib.auth.models import User
from django.template.loader import render_to_string
@@ -53,11 +53,15 @@ def send_approval_email(video):
"""
profile = video.user.profile
with use_lang(profile.locale if profile else settings.LANGUAGE_CODE):
- body = render_to_string('videos/2013/approval_email.html', {
+ text_body = render_to_string('videos/2013/approval_email.ltxt', {
'user': video.user,
'video': video
})
- _send_mail(EMAIL_SUBJECT, body, [video.user.email])
+ html_body = render_to_string('videos/2013/approval_email.html', {
+ 'user': video.user,
+ 'video': video
+ })
+ _send_mail(EMAIL_SUBJECT, text_body, html_body, [video.user.email])
def send_rejection_email(user_id):
@@ -68,13 +72,17 @@ def send_rejection_email(user_id):
user = get_object_or_none(User, id=user_id)
if user:
with use_lang(user.profile.locale):
- body = render_to_string('videos/2013/rejection_email.html', {
+ text_body = render_to_string('videos/2013/rejection_email.ltxt', {
+ 'user': user
+ })
+ html_body = render_to_string('videos/2013/rejection_email.html', {
'user': user
})
- _send_mail(EMAIL_SUBJECT, body, [user.email])
+ _send_mail(EMAIL_SUBJECT, text_body, html_body, [user.email])
-def _send_mail(subject, body, recipients):
- msg = EmailMessage(subject, body, settings.DEFAULT_FROM_EMAIL, recipients)
- msg.content_subtype = 'html'
+def _send_mail(subject, text_body, html_body, recipients):
+ msg = EmailMultiAlternatives(subject, text_body,
+ settings.DEFAULT_FROM_EMAIL, recipients)
+ msg.attach_alternative(html_body, 'text/html')
msg.send()
Please sign in to comment.
Something went wrong with that request. Please try again.