Add html versions of the invite and signup mails

This commit adds html versions of the invite and signup mails and renames
the existing .txt files to the preferred file extensions '.subject', '.html'
and '.txt'. The html versions of the mails are being sent along with the
text-only versions by the 'send_confirmation' function.
This fixes #3134.
This commit is contained in:
Robert Hönig
2017-01-08 16:28:33 +00:00
committed by Tim Abbott
parent 680d30adc2
commit 6ee845d027
8 changed files with 93 additions and 10 deletions

View File

@@ -93,9 +93,9 @@ class ConfirmationManager(models.Manager):
return getattr(settings, 'EMAIL_CONFIRMATION_DAYS', 10)
def send_confirmation(self, obj, email_address, additional_context=None,
subject_template_path=None, body_template_path=None,
subject_template_path=None, body_template_path=None, html_body_template_path=None,
host=None):
# type: (ContentType, Text, Optional[Dict[str, Any]], Optional[str], Optional[str], Optional[str]) -> Confirmation
# type: (ContentType, Text, Optional[Dict[str, Any]], Optional[str], Optional[str], Optional[str], Optional[str]) -> Confirmation
confirmation_key = generate_key()
current_site = Site.objects.get_current()
activate_url = self.get_activation_url(confirmation_key, host=host)
@@ -113,8 +113,8 @@ class ConfirmationManager(models.Manager):
else:
template_name = obj._meta.model_name
templates = [
'confirmation/%s_confirmation_email_subject.txt' % (template_name,),
'confirmation/confirmation_email_subject.txt',
'confirmation/%s_confirmation_email.subject' % (template_name,),
'confirmation/confirmation_email.subject',
]
if subject_template_path:
template = loader.get_template(subject_template_path)
@@ -122,15 +122,21 @@ class ConfirmationManager(models.Manager):
template = loader.select_template(templates)
subject = template.render(context).strip().replace(u'\n', u' ') # no newlines, please
templates = [
'confirmation/%s_confirmation_email_body.txt' % (template_name,),
'confirmation/confirmation_email_body.txt',
'confirmation/%s_confirmation_email.txt' % (template_name,),
'confirmation/confirmation_email.txt',
]
if body_template_path:
template = loader.get_template(body_template_path)
else:
template = loader.select_template(templates)
if html_body_template_path:
html_template = loader.get_template(html_body_template_path)
else:
html_template = loader.get_template('confirmation/%s_confirmation_email.html' % (template_name,))
body = template.render(context)
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [email_address])
if html_template:
html_content = html_template.render(context)
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [email_address], html_message=html_content)
return self.create(content_object=obj, date_sent=now(), confirmation_key=confirmation_key)