annotate sat_website/forms.py @ 45:62c23067e86e

improve English texts following recommandations from Florian
author souliane <souliane@mailoo.org>
date Mon, 27 Apr 2015 16:21:45 +0200
parents d721c8ffa22a
children a1e457ac6871
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
3
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
4 """
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
5 SàT website: Salut à Toi's presentation website
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
6 Copyright (C) 2012 Jérôme Poisson (goffi@goffi.org)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
7
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
8 This file is part of SàT website.
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
9
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
10 SàT website is free software: you can redistribute it and/or modify
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
11 it under the terms of the GNU Affero General Public License as published by
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
12 the Free Software Foundation, either version 3 of the License, or
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
13 (at your option) any later version.
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
14
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
15 Foobar is distributed in the hope that it will be useful,
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
18 GNU Affero General Public License for more details.
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
19
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
20 You should have received a copy of the GNU Affero General Public License
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
21 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
22 """
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
23
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
24 from django.utils.translation import ugettext_lazy as _, string_concat, get_language
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from django.utils.html import format_html
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
26 from django.core.mail import send_mail
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from django import forms
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
28 from django.conf import settings
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
29 from collections import OrderedDict
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from email import email
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
31 import utils
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
32
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
33
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
34 ## Fields ##
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
35
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
36
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
37 class Section(forms.Field):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
38 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
39 kwargs['required'] = False
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
40 super(Section, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
41
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
42 class BooleanField(forms.BooleanField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
43 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
44 super(BooleanField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
45
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
46 class CharField(forms.CharField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
47 def __init__(self, label=None, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
48 try:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
49 placeholder = kwargs.pop('placeholder')
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
50 except KeyError:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
51 placeholder = label
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
52
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
53 super(CharField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
54 self.widget.attrs.update({'class': "form-control",
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
55 'placeholder': placeholder})
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
56
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
57 class EmailField(forms.EmailField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
58 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
59 super(EmailField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
60 self.widget.attrs.update({'class': "form-control",
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
61 'placeholder': self.label})
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
62
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
63 class ChoiceField(forms.ChoiceField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
64 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
65 super(ChoiceField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
66 self.widget.attrs.update({'class': "form-control"})
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
67
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
68 def choice_label(self, value):
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
69 """Return the label corresponding to the given value.
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
70
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
71 @param value (unicode): a choice value
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
72 @return: unicode
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
73 """
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
74 for current_value, label in self.choices:
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
75 if unicode(current_value) == unicode(value):
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
76 return unicode(label)
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
77 return u''
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
78
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
79
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
80 ## Forms ##
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
81
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
82
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
83 class RegistrationForm(forms.Form):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
84
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
85 section_1 = Section(label=_(u'Identity'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
86 name = CharField(label=_(u'Name'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
87 surname = CharField(label=_(u'Surname'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
88 address = CharField(label=_(u'Address, postal code, municipality'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
89
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
90 section_2 = Section(label=_(u'Contacts'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
91 email = EmailField(label=_(u'Email address'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
92 email_confirmation = EmailField(label=_(u'Email address confirmation'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
93 jid = EmailField(required=False, label=_(u'Jabber ID (for example your SàT login)'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
94
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
95 section_3 = Section(label=_(u'Subscription'))
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
96 subscription_amount = ChoiceField(choices=[(amount, u"%s €" % amount) for amount in utils.get_asso_subscr_amounts()])
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
97
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
98 section_3b = Section(label="")
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
99 payment_method = ChoiceField(choices=[(u"card", _(u"Credit or debit card")), (u"transfer", _(u"Bank transfer"))],
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
100 help_text=_(u'Choose "Credit or debit card" to pay via CB, Visa or Mastercard using a secure banking service. Choose "Bank transfer" to proceed manually with the association\'s IBAN/BIC numbers. For both methods, we will first send you an email containing all the details.'), widget=forms.RadioSelect)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
101
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
102 section_5 = Section(label=_(u'Reference'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
103 ref = CharField(required=False, label=_(u"Reference"), placeholder=_(u"Adherent number in case of a renewal"))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
104
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
105 section_6 = Section(label=_(u'Comment'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
106 comment = CharField(required=False, label=_(u"Comment"), placeholder="", widget=forms.Textarea(attrs={'rows': 3}))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
107
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
108 def html_link(url, label):
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
109 return string_concat('<a target="#" href="', url, '">', label, '</a>')
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
110
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
111 agreement_label = [_(u"I read the "),
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
112 html_link(settings.ASSO_URL_STATUTES, _(u"Statutes")),
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
113 _(u" and "),
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
114 html_link(settings.ASSO_URL_RULES, _(u"Rules")),
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
115 _(u" of the association, and agree to both of them."),
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
116 ]
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
117 agreement_confirmation = BooleanField(label=string_concat(*agreement_label))
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
118
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
119 def sections(self):
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
120 """Get the fields grouped in sections.
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
121
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
122 @return: OrderedDict binding section name to a list of fields
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
123 """
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
124 sections = OrderedDict()
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
125 current_section = None
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
126 for field in self:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
127 if isinstance(field.field, Section):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
128 current_section = sections.setdefault(field.label, [])
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
129 else:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
130 current_section.append(field)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
131 return sections
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
132
44
d721c8ffa22a misc updates:
souliane <souliane@mailoo.org>
parents: 41
diff changeset
133 def clean(self):
d721c8ffa22a misc updates:
souliane <souliane@mailoo.org>
parents: 41
diff changeset
134 cleaned_data = super(RegistrationForm, self).clean()
d721c8ffa22a misc updates:
souliane <souliane@mailoo.org>
parents: 41
diff changeset
135 email = cleaned_data.get("email")
d721c8ffa22a misc updates:
souliane <souliane@mailoo.org>
parents: 41
diff changeset
136 email_confirmation = cleaned_data.get("email_confirmation")
d721c8ffa22a misc updates:
souliane <souliane@mailoo.org>
parents: 41
diff changeset
137
d721c8ffa22a misc updates:
souliane <souliane@mailoo.org>
parents: 41
diff changeset
138 if email and email_confirmation and email != email_confirmation:
d721c8ffa22a misc updates:
souliane <souliane@mailoo.org>
parents: 41
diff changeset
139 msg = _(u"Passwords don't match.")
d721c8ffa22a misc updates:
souliane <souliane@mailoo.org>
parents: 41
diff changeset
140 self.add_error('email_confirmation', msg)
d721c8ffa22a misc updates:
souliane <souliane@mailoo.org>
parents: 41
diff changeset
141
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
142
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
143 def results(self, user_readable=True):
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
144 """Get the results submitted by the user as a list of couple. Keep the
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
145 pertinent fields and filter out the inappropriate ones.
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
146
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
147 @param user_readable: set to True to prefer the field labels to their names
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
148 @return: list of couple (name, value) or (label, value)
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
149 """
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
150 if not self.is_valid():
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
151 return ''
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
152 results = []
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
153 for field in self:
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
154 if isinstance(field.field, Section):
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
155 continue
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
156 if field.name in ('email_confirmation', 'agreement_confirmation') or not field.value():
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
157 continue
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
158 if field.name == "payment_method" and self['subscription_amount'].value() == "0":
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
159 continue
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
160 value = field.value()
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
161 if user_readable:
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
162 if isinstance(field.field, ChoiceField):
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
163 value = field.field.choice_label(value)
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
164 results.append((field.label, value))
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
165 else:
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
166 results.append((field.name, value))
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
167 if user_readable:
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
168 results.append((_(u'Language'), utils.get_language_name_local(get_language())))
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
169 else:
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
170 results.append(('lang', get_language()))
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
171 return results
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
172
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
173 def result_as_string(self, user_readable=True):
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
174 """Get the result as a string to be sent for example via email.
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
175
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
176 @param user_readable: set to True to prefer the field labels to their names
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
177 @return: list of couple (name, value) or (label, value)
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
178 """
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
179 return '\n'.join([name + ': ' + value for name, value in self.results(user_readable)])
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
180
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
181 def process_submitted_data(self):
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
182 if not self.is_valid():
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
183 return
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
184 # send email to user
45
62c23067e86e improve English texts following recommandations from Florian
souliane <souliane@mailoo.org>
parents: 44
diff changeset
185 send_mail(_(u'Subscription to Salut à Toi'), self.result_as_string(True), settings.EMAIL_BACKEND, [self['email'].value()], fail_silently=False)
41
1a0f24401866 send adhesion form results via email to the admins and the new member
souliane <souliane@mailoo.org>
parents: 40
diff changeset
186 # send email to admins
45
62c23067e86e improve English texts following recommandations from Florian
souliane <souliane@mailoo.org>
parents: 44
diff changeset
187 send_mail(_(u'Subscription to Salut à Toi'), self.result_as_string(False), settings.EMAIL_BACKEND, [email for name, email in settings.ADMINS], fail_silently=False)