comparison 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
comparison
equal deleted inserted replaced
33:73c6333fd124 34:9d553570cc61
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 """
5 SàT website: Salut à Toi's presentation website
6 Copyright (C) 2012 Jérôme Poisson (goffi@goffi.org)
7
8 This file is part of SàT website.
9
10 SàT website is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Affero General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 Foobar is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Affero General Public License for more details.
19
20 You should have received a copy of the GNU Affero General Public License
21 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
22 """
23
24 from django.utils.translation import ugettext_lazy as _
25 from django.utils.html import format_html
26 from django import forms
27 from collections import OrderedDict
28 from email import email
29 import utils
30
31
32 ## Fields ##
33
34
35 class Section(forms.Field):
36 def __init__(self, *args, **kwargs):
37 kwargs['required'] = False
38 super(Section, self).__init__(*args, **kwargs)
39
40 class BooleanField(forms.BooleanField):
41 def __init__(self, *args, **kwargs):
42 super(BooleanField, self).__init__(*args, **kwargs)
43
44 class CharField(forms.CharField):
45 def __init__(self, label=None, *args, **kwargs):
46 try:
47 placeholder = kwargs.pop('placeholder')
48 except KeyError:
49 placeholder = label
50
51 super(CharField, self).__init__(*args, **kwargs)
52 self.widget.attrs.update({'class': "form-control",
53 'placeholder': placeholder})
54
55 class EmailField(forms.EmailField):
56 def __init__(self, *args, **kwargs):
57 super(EmailField, self).__init__(*args, **kwargs)
58 self.widget.attrs.update({'class': "form-control",
59 'placeholder': self.label})
60
61 class ChoiceField(forms.ChoiceField):
62 def __init__(self, *args, **kwargs):
63 super(ChoiceField, self).__init__(*args, **kwargs)
64 self.widget.attrs.update({'class': "form-control"})
65
66
67 ## Forms ##
68
69
70 class RegistrationForm(forms.Form):
71
72 section_1 = Section(label=_(u'Identity'))
73 name = CharField(label=_(u'Name'))
74 surname = CharField(label=_(u'Surname'))
75 address = CharField(label=_(u'Address, postal code, municipality'))
76
77 section_2 = Section(label=_(u'Contacts'))
78 email = EmailField(label=_(u'Email address'))
79 email_confirmation = EmailField(label=_(u'Email address confirmation'))
80 jid = EmailField(required=False, label=_(u'Jabber ID (for example your SàT login)'))
81
82 section_3 = Section(label=_(u'Subscription'))
83 subscription_amount = ChoiceField(choices=[(amount, "%s €" % amount) for amount in utils.get_asso_subscr_amounts()])
84
85 section_3b = Section(label="")
86 payment_method = ChoiceField(choices=[("card", _(u"Credit or debit card")), ("transfer", _(u"Bank transfer"))],
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)
88
89 section_5 = Section(label=_(u'Reference'))
90 ref = CharField(required=False, label=_(u"Reference"), placeholder=_(u"Adherent number in case of a renewal"))
91
92 section_6 = Section(label=_(u'Comment'))
93 comment = CharField(required=False, label=_(u"Comment"), placeholder="", widget=forms.Textarea(attrs={'rows': 3}))
94
95 confirm = BooleanField(label=_(u"I read the Rules of Procedure"))
96
97 def sections(self):
98 sections = OrderedDict()
99 current_section = None
100 for field in self:
101 if isinstance(field.field, Section):
102 current_section = sections.setdefault(field.label, [])
103 else:
104 current_section.append(field)
105 return sections