annotate sat_website/forms.py @ 34:9d553570cc61

add adhesion_form.html and thank_you.html
author souliane <souliane@mailoo.org>
date Tue, 27 Jan 2015 08:20:30 +0100
parents
children dfe7139dae0a
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
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from django.utils.translation import ugettext_lazy as _
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
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from collections import OrderedDict
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from email import email
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
29 import utils
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
30
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 ## Fields ##
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
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
35 class Section(forms.Field):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
36 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
37 kwargs['required'] = False
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
38 super(Section, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
39
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
40 class BooleanField(forms.BooleanField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
41 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
42 super(BooleanField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
43
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
44 class CharField(forms.CharField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
45 def __init__(self, label=None, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
46 try:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
47 placeholder = kwargs.pop('placeholder')
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
48 except KeyError:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
49 placeholder = label
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
50
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
51 super(CharField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
52 self.widget.attrs.update({'class': "form-control",
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
53 'placeholder': placeholder})
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
54
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
55 class EmailField(forms.EmailField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
56 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
57 super(EmailField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
58 self.widget.attrs.update({'class': "form-control",
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
59 'placeholder': self.label})
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
60
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
61 class ChoiceField(forms.ChoiceField):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
62 def __init__(self, *args, **kwargs):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
63 super(ChoiceField, self).__init__(*args, **kwargs)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
64 self.widget.attrs.update({'class': "form-control"})
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
65
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 ## Forms ##
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
68
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 class RegistrationForm(forms.Form):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
71
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
72 section_1 = Section(label=_(u'Identity'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
73 name = CharField(label=_(u'Name'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
74 surname = CharField(label=_(u'Surname'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
75 address = CharField(label=_(u'Address, postal code, municipality'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
76
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
77 section_2 = Section(label=_(u'Contacts'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
78 email = EmailField(label=_(u'Email address'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
79 email_confirmation = EmailField(label=_(u'Email address confirmation'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
80 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
81
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
82 section_3 = Section(label=_(u'Subscription'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
83 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
84
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
85 section_3b = Section(label="")
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
86 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
87 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
88
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
89 section_5 = Section(label=_(u'Reference'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
90 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
91
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
92 section_6 = Section(label=_(u'Comment'))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
93 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
94
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
95 confirm = BooleanField(label=_(u"I read the Rules of Procedure"))
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
96
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
97 def sections(self):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
98 sections = OrderedDict()
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
99 current_section = None
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
100 for field in self:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
101 if isinstance(field.field, Section):
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
102 current_section = sections.setdefault(field.label, [])
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
103 else:
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
104 current_section.append(field)
9d553570cc61 add adhesion_form.html and thank_you.html
souliane <souliane@mailoo.org>
parents:
diff changeset
105 return sections