diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sat_website/forms.py	Tue Jan 27 08:20:30 2015 +0100
@@ -0,0 +1,105 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+"""
+SàT website: Salut à Toi's presentation website
+Copyright (C) 2012  Jérôme Poisson (goffi@goffi.org)
+
+This file is part of SàT website.
+
+SàT website is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Foobar is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+from django.utils.translation import ugettext_lazy as _
+from django.utils.html import format_html
+from django import forms
+from collections import OrderedDict
+from email import email
+import utils
+
+
+## Fields ##
+
+
+class Section(forms.Field):
+    def __init__(self, *args, **kwargs):
+        kwargs['required'] = False
+        super(Section, self).__init__(*args, **kwargs)
+
+class BooleanField(forms.BooleanField):
+    def __init__(self, *args, **kwargs):
+        super(BooleanField, self).__init__(*args, **kwargs)
+
+class CharField(forms.CharField):
+    def __init__(self, label=None, *args, **kwargs):
+        try:
+            placeholder = kwargs.pop('placeholder')
+        except KeyError:
+            placeholder = label
+
+        super(CharField, self).__init__(*args, **kwargs)
+        self.widget.attrs.update({'class': "form-control",
+                                  'placeholder': placeholder})
+
+class EmailField(forms.EmailField):
+    def __init__(self, *args, **kwargs):
+        super(EmailField, self).__init__(*args, **kwargs)
+        self.widget.attrs.update({'class': "form-control",
+                                  'placeholder': self.label})
+
+class ChoiceField(forms.ChoiceField):
+    def __init__(self, *args, **kwargs):
+        super(ChoiceField, self).__init__(*args, **kwargs)
+        self.widget.attrs.update({'class': "form-control"})
+
+
+## Forms ##
+
+
+class RegistrationForm(forms.Form):
+
+    section_1 = Section(label=_(u'Identity'))
+    name = CharField(label=_(u'Name'))
+    surname = CharField(label=_(u'Surname'))
+    address = CharField(label=_(u'Address, postal code, municipality'))
+
+    section_2 = Section(label=_(u'Contacts'))
+    email = EmailField(label=_(u'Email address'))
+    email_confirmation = EmailField(label=_(u'Email address confirmation'))
+    jid = EmailField(required=False, label=_(u'Jabber ID (for example your SàT login)'))
+
+    section_3 = Section(label=_(u'Subscription'))
+    subscription_amount = ChoiceField(choices=[(amount, "%s €" % amount) for amount in utils.get_asso_subscr_amounts()])
+
+    section_3b = Section(label="")
+    payment_method = ChoiceField(choices=[("card", _(u"Credit or debit card")), ("transfer", _(u"Bank transfer"))],
+                               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)
+
+    section_5 = Section(label=_(u'Reference'))
+    ref = CharField(required=False, label=_(u"Reference"), placeholder=_(u"Adherent number in case of a renewal"))
+
+    section_6 = Section(label=_(u'Comment'))
+    comment = CharField(required=False, label=_(u"Comment"), placeholder="", widget=forms.Textarea(attrs={'rows': 3}))
+
+    confirm = BooleanField(label=_(u"I read the Rules of Procedure"))
+
+    def sections(self):
+        sections = OrderedDict()
+        current_section = None
+        for field in self:
+            if isinstance(field.field, Section):
+                current_section = sections.setdefault(field.label, [])
+            else:
+                current_section.append(field)
+        return sections