annotate sat_website/forms.py @ 40:dfe7139dae0a

add links to the statutes and rules of the association in the adhesion form
author souliane <souliane@mailoo.org>
date Tue, 03 Feb 2015 15:14:42 +0100
parents 9d553570cc61
children 1a0f24401866
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
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
24 from django.utils.translation import ugettext_lazy as _, string_concat
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
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
26 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
27 from django.conf import settings
34
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from collections import OrderedDict
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
29 from email import email
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
30 import utils
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
31
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 ## Fields ##
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
34
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 class Section(forms.Field):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
37 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
38 kwargs['required'] = False
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
39 super(Section, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
40
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
41 class BooleanField(forms.BooleanField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
42 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
43 super(BooleanField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
44
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
45 class CharField(forms.CharField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
46 def __init__(self, label=None, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
47 try:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
48 placeholder = kwargs.pop('placeholder')
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
49 except KeyError:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
50 placeholder = label
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
51
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
52 super(CharField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
53 self.widget.attrs.update({'class': "form-control",
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
54 'placeholder': placeholder})
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
55
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
56 class EmailField(forms.EmailField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
57 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
58 super(EmailField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
59 self.widget.attrs.update({'class': "form-control",
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
60 'placeholder': self.label})
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
61
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
62 class ChoiceField(forms.ChoiceField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
63 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
64 super(ChoiceField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
65 self.widget.attrs.update({'class': "form-control"})
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
66
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
67
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
68 ## Forms ##
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
69
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
70
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
71 class RegistrationForm(forms.Form):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
72
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
73 section_1 = Section(label=_(u'Identity'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
74 name = CharField(label=_(u'Name'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
75 surname = CharField(label=_(u'Surname'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
76 address = CharField(label=_(u'Address, postal code, municipality'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
77
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
78 section_2 = Section(label=_(u'Contacts'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
79 email = EmailField(label=_(u'Email address'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
80 email_confirmation = EmailField(label=_(u'Email address confirmation'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
81 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
82
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
83 section_3 = Section(label=_(u'Subscription'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
84 subscription_amount = ChoiceField(choices=[(amount, "%s €" % amount) for amount in utils.get_asso_subscr_amounts()])
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
85
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
86 section_3b = Section(label="")
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
87 payment_method = ChoiceField(choices=[("card", _(u"Credit or debit card")), ("transfer", _(u"Bank transfer"))],
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
88 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
89
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
90 section_5 = Section(label=_(u'Reference'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
91 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
92
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
93 section_6 = Section(label=_(u'Comment'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
94 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
95
40
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
96 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
97 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
98
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
99 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
100 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
101 _(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
102 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
103 _(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
104 ]
dfe7139dae0a add links to the statutes and rules of the association in the adhesion form
souliane <souliane@mailoo.org>
parents: 34
diff changeset
105 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
106
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
107 def sections(self):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
108 sections = OrderedDict()
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
109 current_section = None
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
110 for field in self:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
111 if isinstance(field.field, Section):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
112 current_section = sections.setdefault(field.label, [])
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
113 else:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
114 current_section.append(field)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
115 return sections