Mercurial > sat_legacy_website
diff sat_website/forms.py @ 65:26353615cc2e
fixed email sending in form
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 16 May 2015 17:28:19 +0200 |
parents | 0d20fb28c32e |
children | 64977f537e9b |
line wrap: on
line diff
--- a/sat_website/forms.py Sat May 16 10:13:52 2015 +0200 +++ b/sat_website/forms.py Sat May 16 17:28:19 2015 +0200 @@ -22,12 +22,10 @@ """ from django.utils.translation import ugettext_lazy as _, ugettext, string_concat, get_language -from django.utils.html import format_html from django.core.mail import send_mail from django import forms from django.conf import settings from collections import OrderedDict -from email import email import unicodecsv import utils import re @@ -69,7 +67,7 @@ def choice_label(self, value): """Return the label corresponding to the given value. - + @param value (unicode): a choice value @return: unicode """ @@ -78,7 +76,7 @@ return unicode(label) return u'' - + ## Forms ## @@ -122,9 +120,9 @@ def sections(self): """Get the fields grouped in sections. - + @return: OrderedDict binding section name to a list of fields - """ + """ sections = OrderedDict() current_section = None for field in self: @@ -146,7 +144,7 @@ def results(self, user_readable=True): """Get the results submitted by the user as a list. - + @param user_readable: (bool) set to True to prefer the fields' labels to their names, also filter out the empty fields. @return: list of couple (name, value) or (label, value) @@ -197,7 +195,7 @@ @return: unicode """ return '\n'.join([name + ': ' + value for name, value in self.results(user_readable)]) - + def prepareResultForUser(self): """Get the email body to send to the subscriber. @@ -214,7 +212,7 @@ } HEADER = ugettext(u"""Tank you, {name}! - + We received your submission and we are happy to count you in the members of the association. """) @@ -269,8 +267,8 @@ if not self.is_valid(): return # send email to user - send_mail(_(u'Subscription to Salut à Toi'), self.prepareResultForUser(), settings.EMAIL_BACKEND, [self['email'].value()], fail_silently=False) + send_mail(_(u'Subscription to Salut à Toi'), self.prepareResultForUser(), settings.FORM_FROM_EMAIL, [self['email'].value()], fail_silently=False) # send email to admins - send_mail(_(u'Subscription to Salut à Toi'), self.prepareResultForAdmin(), settings.EMAIL_BACKEND, [email for name, email in settings.ADMINS], fail_silently=False) + send_mail(_(u'Subscription to Salut à Toi'), self.prepareResultForAdmin(), settings.FORM_FROM_EMAIL, settings.FORM_TO_EMAILS, fail_silently=False) # save to a CSV file self.writeResultToCSV()