Commit a1f33218 authored by Michal Čihař's avatar Michal Čihař

Simplify email sending

parent 0645e2f5
...@@ -81,8 +81,7 @@ class RegistrationTemplateView(TemplateView): ...@@ -81,8 +81,7 @@ class RegistrationTemplateView(TemplateView):
return context return context
def mail_admins_sender(subject, message, sender, fail_silently=False, def mail_admins_contact(subject, message, context, sender):
connection=None, html_message=None):
''' '''
Sends a message to the admins, as defined by the ADMINS setting. Sends a message to the admins, as defined by the ADMINS setting.
''' '''
...@@ -90,17 +89,13 @@ def mail_admins_sender(subject, message, sender, fail_silently=False, ...@@ -90,17 +89,13 @@ def mail_admins_sender(subject, message, sender, fail_silently=False,
return return
mail = EmailMultiAlternatives( mail = EmailMultiAlternatives(
u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject % context),
message, message % context,
to=[a[1] for a in settings.ADMINS], to=[a[1] for a in settings.ADMINS],
headers={'Reply-To': sender}, headers={'Reply-To': sender},
connection=connection
) )
if html_message: mail.send(fail_silently=False)
mail.attach_alternative(html_message, 'text/html')
mail.send(fail_silently=fail_silently)
@login_required @login_required
...@@ -189,9 +184,10 @@ def contact(request): ...@@ -189,9 +184,10 @@ def contact(request):
if request.method == 'POST': if request.method == 'POST':
form = ContactForm(request.POST) form = ContactForm(request.POST)
if form.is_valid(): if form.is_valid():
mail_admins_sender( mail_admins_contact(
form.cleaned_data['subject'], '%(subject)s',
CONTACT_TEMPLATE % form.cleaned_data, CONTACT_TEMPLATE,
form.cleaned_data,
form.cleaned_data['email'], form.cleaned_data['email'],
) )
messages.info( messages.info(
...@@ -230,9 +226,10 @@ def hosting(request): ...@@ -230,9 +226,10 @@ def hosting(request):
if request.method == 'POST': if request.method == 'POST':
form = HostingForm(request.POST) form = HostingForm(request.POST)
if form.is_valid(): if form.is_valid():
mail_admins_sender( mail_admins_contact(
'Hosting request for %(project)s' % form.cleaned_data, 'Hosting request for %(project)s',
HOSTING_TEMPLATE % form.cleaned_data, HOSTING_TEMPLATE,
form.cleaned_data,
form.cleaned_data['email'], form.cleaned_data['email'],
) )
messages.info( messages.info(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment