comparison sat_website/forms.py @ 149:b1c16cd53b62

update django to version 1.11, refactor project structure, better PEP-8 compliance
author souliane <souliane@mailoo.org>
date Tue, 17 Oct 2017 04:11:21 +0200
parents 75a95a1dfeb6
children
comparison
equal deleted inserted replaced
148:75a95a1dfeb6 149:b1c16cd53b62
79 79
80 80
81 ## Forms ## 81 ## Forms ##
82 82
83 83
84 def html_link(url, label):
85 return string_concat('<a target="#" href="', url, '">', label, '</a>')
86
87
84 class RegistrationForm(forms.Form): 88 class RegistrationForm(forms.Form):
85 89
86 section_1 = Section(label=_(u'Identity')) 90 section_1 = Section(label=_(u'Identity'))
87 name = CharField(label=_(u'Given name')) 91 name = CharField(label=_(u'Given name'))
88 surname = CharField(label=_(u'Family name')) 92 surname = CharField(label=_(u'Family name'))
101 105
102 section_5 = Section(label=_(u'Comment')) 106 section_5 = Section(label=_(u'Comment'))
103 comment = CharField(required=False, label=_(u"Comment"), placeholder="", widget=forms.Textarea(attrs={'rows': 3})) 107 comment = CharField(required=False, label=_(u"Comment"), placeholder="", widget=forms.Textarea(attrs={'rows': 3}))
104 108
105 mailing = BooleanField(required=False, label=_(u"I would like to subscribe to the adherents' mailing list.")) 109 mailing = BooleanField(required=False, label=_(u"I would like to subscribe to the adherents' mailing list."))
106
107 def html_link(url, label):
108 return string_concat('<a target="#" href="', url, '">', label, '</a>')
109 110
110 agreement_label = [_(u"I read the "), 111 agreement_label = [_(u"I read the "),
111 html_link(settings.ASSO_URL_STATUTES, _(u"Statutes")), 112 html_link(settings.ASSO_URL_STATUTES, _(u"Statutes")),
112 _(u" and "), 113 _(u" and "),
113 html_link(settings.ASSO_URL_RULES, _(u"Rules")), 114 html_link(settings.ASSO_URL_RULES, _(u"Rules")),
255 An email has been automatically sent to {name}, no additional action is required from your side.""") 256 An email has been automatically sent to {name}, no additional action is required from your side.""")
256 257
257 return MSG.format(**data) 258 return MSG.format(**data)
258 259
259 def writeResultToCSV(self): 260 def writeResultToCSV(self):
260 result = [unicode(value) for key, value in self.results(False)] 261 result = [unicode(value) for dummy, value in self.results(False)]
261 with open(settings.ASSO_SUBSCR_CSV, 'a+') as csvfile: 262 with open(settings.ASSO_SUBSCR_CSV, 'a+') as csvfile:
262 writer = unicodecsv.writer(csvfile, delimiter=';') 263 writer = unicodecsv.writer(csvfile, delimiter=';')
263 writer.writerow(result) 264 writer.writerow(result)
264 265
265 def process_submitted_data(self): 266 def process_submitted_data(self):
266 """Send emails to the subscriber and the admins.""" 267 """Send emails to the subscriber and the admins."""
267 if not self.is_valid(): 268 if not self.is_valid():
268 return 269 return
269 # send email to user 270 # send email to user
270 send_mail(_(u'Subscription to Salut à Toi'), self.prepareResultForUser(), settings.FORM_FROM_EMAIL, [self['email'].value()], fail_silently=False) 271 send_mail(
272 _(u'Subscription to Salut à Toi'),
273 self.prepareResultForUser(),
274 settings.DEFAULT_FROM_EMAIL,
275 [self['email'].value()],
276 fail_silently=False
277 )
271 # send email to admins 278 # send email to admins
272 send_mail(_(u'Subscription to Salut à Toi'), self.prepareResultForAdmin(), settings.FORM_FROM_EMAIL, settings.FORM_TO_EMAILS, fail_silently=False) 279 send_mail(
280 _(u'Subscription to Salut à Toi'),
281 self.prepareResultForAdmin(),
282 settings.DEFAULT_FROM_EMAIL,
283 [email for dummy, email in settings.ADMINS],
284 fail_silently=False
285 )
273 # save to a CSV file 286 # save to a CSV file
274 self.writeResultToCSV() 287 self.writeResultToCSV()