Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Fix bug 852214: Add support for multipart text and html emails.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kelly committed Mar 28, 2013
1 parent 7349907 commit 47d849b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 22 deletions.
12 changes: 12 additions & 0 deletions flicks/base/templates/email_base.ltxt
Original file line number Diff line number Diff line change
@@ -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') }}
17 changes: 3 additions & 14 deletions flicks/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions flicks/videos/templates/videos/2013/approval_email.ltxt
Original file line number Diff line number Diff line change
@@ -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 %}
12 changes: 12 additions & 0 deletions flicks/videos/templates/videos/2013/rejection_email.ltxt
Original file line number Diff line number Diff line change
@@ -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 %}

24 changes: 16 additions & 8 deletions flicks/videos/util.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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()

0 comments on commit 47d849b

Please sign in to comment.