Mercurial > sat_legacy_website
comparison sat_website/forms.py @ 96:c868187b8d00
add the current date in the subscription form's results
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 25 Jun 2015 15:06:07 +0200 |
parents | dc8a30f6c369 |
children | d0cd185f9b61 |
comparison
equal
deleted
inserted
replaced
95:dc8a30f6c369 | 96:c868187b8d00 |
---|---|
24 from django.utils.translation import ugettext_lazy as _, ugettext, string_concat, get_language | 24 from django.utils.translation import ugettext_lazy as _, ugettext, string_concat, get_language |
25 from django.core.mail import send_mail | 25 from django.core.mail import send_mail |
26 from django import forms | 26 from django import forms |
27 from django.conf import settings | 27 from django.conf import settings |
28 from collections import OrderedDict | 28 from collections import OrderedDict |
29 from time import strftime | |
29 import unicodecsv | 30 import unicodecsv |
30 import utils | 31 import utils |
31 import re | 32 import re |
32 | 33 |
33 | 34 |
150 @return: list of couple (name, value) or (label, value) | 151 @return: list of couple (name, value) or (label, value) |
151 """ | 152 """ |
152 if not self.is_valid(): | 153 if not self.is_valid(): |
153 return None | 154 return None |
154 results = [] | 155 results = [] |
156 | |
157 date = strftime("%Y-%m-%d") | |
158 if user_readable: | |
159 results.append((_(u"Date"), date)) | |
160 else: | |
161 results.append(('date', date)) | |
162 | |
155 for field in self: | 163 for field in self: |
156 if isinstance(field.field, Section): | 164 if isinstance(field.field, Section): |
157 continue # filter out section fields | 165 continue # filter out section fields |
158 if field.name in ('email_confirmation', 'agreement_confirmation'): | 166 if field.name in ('email_confirmation', 'agreement_confirmation'): |
159 continue # filter out confirmation fields | 167 continue # filter out confirmation fields |
172 else: | 180 else: |
173 key = field.label | 181 key = field.label |
174 if isinstance(field.field, ChoiceField): | 182 if isinstance(field.field, ChoiceField): |
175 value = field.field.choice_label(value) | 183 value = field.field.choice_label(value) |
176 results.append((key, value)) | 184 results.append((key, value)) |
185 | |
177 if user_readable: | 186 if user_readable: |
178 results.append((_(u'Language'), utils.get_language_name_local(get_language()))) | 187 results.append((_(u'Language'), utils.get_language_name_local(get_language()))) |
179 else: | 188 else: |
180 results.append(('lang', get_language())) | 189 results.append(('lang', get_language())) |
190 | |
181 return results | 191 return results |
182 | 192 |
183 def result_as_dict(self, user_readable=True): | 193 def result_as_dict(self, user_readable=True): |
184 """Get the results submitted by the user as an OrderedDict. | 194 """Get the results submitted by the user as an OrderedDict. |
185 | 195 |