Mercurial > sat_legacy_website
comparison sat_website/forms.py @ 60:0d20fb28c32e
many small changes:
- set opacity 0.85 to libervia screenshot on the main page
- remove videos from the repository (stored on external ftp)
- more details in the README concerning the i18n
- settings can be overriden by an external file (for the stats)
- add in basic features.html a button to experimental features
- add a link to the SàT MUC in downloads section
- add link to bugzilla + improve other links in dev/community
- add + symbol for projects using standard blogging system
- add ~ symbol for projects being no communication tool
- save subscription form results to a text file
- update press.py and links.py
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 15 May 2015 17:15:40 +0200 |
parents | bfa8009f0769 |
children | 26353615cc2e |
comparison
equal
deleted
inserted
replaced
59:01738ae70f2d | 60:0d20fb28c32e |
---|---|
26 from django.core.mail import send_mail | 26 from django.core.mail import send_mail |
27 from django import forms | 27 from django import forms |
28 from django.conf import settings | 28 from django.conf import settings |
29 from collections import OrderedDict | 29 from collections import OrderedDict |
30 from email import email | 30 from email import email |
31 import unicodecsv | |
31 import utils | 32 import utils |
32 import re | 33 import re |
33 | 34 |
34 | 35 |
35 ## Fields ## | 36 ## Fields ## |
144 | 145 |
145 | 146 |
146 def results(self, user_readable=True): | 147 def results(self, user_readable=True): |
147 """Get the results submitted by the user as a list. | 148 """Get the results submitted by the user as a list. |
148 | 149 |
149 Keep the pertinent fields and filter out the inappropriate ones. | 150 @param user_readable: (bool) set to True to prefer the fields' labels |
150 @param user_readable: (bool) set to True to prefer the field labels to their names | 151 to their names, also filter out the empty fields. |
151 @return: list of couple (name, value) or (label, value) | 152 @return: list of couple (name, value) or (label, value) |
152 """ | 153 """ |
153 if not self.is_valid(): | 154 if not self.is_valid(): |
154 return None | 155 return None |
155 results = [] | 156 results = [] |
156 for field in self: | 157 for field in self: |
157 if isinstance(field.field, Section): | 158 if isinstance(field.field, Section): |
158 continue | 159 continue # filter out section fields |
159 if field.name in ('email_confirmation', 'agreement_confirmation') or not field.value(): | 160 if field.name in ('email_confirmation', 'agreement_confirmation'): |
160 continue | 161 continue # filter out confirmation fields |
161 if field.name == "payment_method" and self['subscription_amount'].value() == "0": | 162 if user_readable and not field.value(): |
162 continue | 163 continue # filter out empty value |
164 if user_readable and field.name == "payment_method" and self['subscription_amount'].value() == "0": | |
165 continue # filter out fields that are not pertinent for the user | |
163 key = field.name | 166 key = field.name |
164 if isinstance(field.field, BooleanField) and user_readable: | 167 if isinstance(field.field, BooleanField) and user_readable: |
165 value = ugettext(u"yes") if field.value() else ugettext(u"no") | 168 value = ugettext(u"yes") if field.value() else ugettext(u"no") |
166 else: | 169 else: |
167 value = re.sub(r"[\n\r]+", ", ", unicode(field.value())) | 170 value = re.sub(r"[\n\r]+", ", ", unicode(field.value())) |
253 | 256 |
254 An email has been automatically sent to {name}, no additional action is required from your side.""") | 257 An email has been automatically sent to {name}, no additional action is required from your side.""") |
255 | 258 |
256 return MSG.format(**data) | 259 return MSG.format(**data) |
257 | 260 |
261 def writeResultToCSV(self): | |
262 result = [unicode(value) for key, value in self.results(False)] | |
263 with open(settings.ASSO_SUBSCR_CSV, 'a+') as csvfile: | |
264 writer = unicodecsv.UnicodeWriter(csvfile, delimiter=';') | |
265 writer.writerow(result) | |
266 | |
258 def process_submitted_data(self): | 267 def process_submitted_data(self): |
259 """Send emails to the subscriber and the admins.""" | 268 """Send emails to the subscriber and the admins.""" |
260 if not self.is_valid(): | 269 if not self.is_valid(): |
261 return | 270 return |
262 # send email to user | 271 # send email to user |
263 send_mail(_(u'Subscription to Salut à Toi'), self.prepareResultForUser(), settings.EMAIL_BACKEND, [self['email'].value()], fail_silently=False) | 272 send_mail(_(u'Subscription to Salut à Toi'), self.prepareResultForUser(), settings.EMAIL_BACKEND, [self['email'].value()], fail_silently=False) |
264 # send email to admins | 273 # send email to admins |
265 send_mail(_(u'Subscription to Salut à Toi'), self.prepareResultForAdmin(), settings.EMAIL_BACKEND, [email for name, email in settings.ADMINS], fail_silently=False) | 274 send_mail(_(u'Subscription to Salut à Toi'), self.prepareResultForAdmin(), settings.EMAIL_BACKEND, [email for name, email in settings.ADMINS], fail_silently=False) |
275 # save to a CSV file | |
276 self.writeResultToCSV() |