Mercurial > sat_legacy_website
changeset 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 | 73c6333fd124 |
children | 10ce34ab389a |
files | sat_website/forms.py sat_website/templatetags/utils.py sat_website/views.py static/css/sat_website.css static/js/sat_website.js templates/sat_website/adhesion_form.html templates/sat_website/thank_you.html |
diffstat | 7 files changed, 322 insertions(+), 4 deletions(-) [+] |
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
--- a/sat_website/templatetags/utils.py Tue Jan 27 08:07:15 2015 +0100 +++ b/sat_website/templatetags/utils.py Tue Jan 27 08:20:30 2015 +0100 @@ -1,4 +1,5 @@ from django import template +from django.forms import RadioSelect, CheckboxInput register = template.Library() @register.filter @@ -13,6 +14,36 @@ return type(value) == tuple @register.filter +def is_radio(value): + """Tell if this value is a RadioSelect or not. + + @param value (obj): any object + @return: True if value is a RadioSelect + """ + return type(value) == RadioSelect + +@register.filter +def is_checkbox(value): + """Tell if this value is a CheckboxInput or not. + + @param value (obj): any object + @return: True if value is a CheckboxInput + """ + return type(value) == CheckboxInput + +@register.filter +def selected_label(select): + """Return the label of the single selected option. + + @param select: a BoundField object bound to a Select with single choice. + @return: unicode + """ + for value, label in select.field.choices: + if value == select.value(): + return label + return None + +@register.filter def buffer(value, n): """Split values in sub-lists of n elements.
--- a/sat_website/views.py Tue Jan 27 08:07:15 2015 +0100 +++ b/sat_website/views.py Tue Jan 27 08:20:30 2015 +0100 @@ -24,8 +24,9 @@ from django.shortcuts import render_to_response from django.core.context_processors import csrf from django.utils.translation import ugettext_lazy as _ +from django.template import RequestContext from collections import OrderedDict -import screenshots, social_contract, utils +import screenshots, social_contract, utils, forms CATEGORIES = OrderedDict([('frontends', (_(u"Presentation"), OrderedDict([("features", _(u"Features")), @@ -50,19 +51,21 @@ ("social_contract", _(u"Social contract")), ]) +CATEGORIES_HIDDEN = ('adhesion_form', 'thank_you') + def overview(request): return render_to_response('sat_website/overview.html') def generic_cat(request, category): - context = { + context = RequestContext(request, { "available_languages": ['fr', 'en'], "categories": CATEGORIES, "categories_right": CATEGORIES_RIGHT, "category": category, - } "libervia_demo_url": utils.get_libervia_demo_url(), "subscription_amounts": utils.get_asso_subscr_amounts(), + }) context.update(csrf(request)) @@ -79,12 +82,23 @@ latest_dl_path, latest_version = utils.get_latest_sat() context["latest_dl_path"] = latest_dl_path context["latest_version"] = latest_version + elif category == "adhesion": + context.update(utils.get_asso_finance_status()) + elif category == "adhesion_form": + if request.method == 'POST': + form = forms.RegistrationForm(request.POST) + if form.is_valid(): + category = 'thank_you' + else: + form = forms.RegistrationForm(initial={'subscription_amount': 10, + 'payment_method': 'card'}) + context['form'] = form def all_keys(cats): subcats = [value[1].keys() for value in cats.values() if isinstance(value, tuple)] return sum(subcats, cats.keys()) - if category in all_keys(CATEGORIES) or category in all_keys(CATEGORIES_RIGHT): + if category in all_keys(CATEGORIES) or category in all_keys(CATEGORIES_RIGHT) or category in CATEGORIES_HIDDEN: return render_to_response('sat_website/%s.html' % (category,), context) else: raise Http404
--- a/static/css/sat_website.css Tue Jan 27 08:07:15 2015 +0100 +++ b/static/css/sat_website.css Tue Jan 27 08:20:30 2015 +0100 @@ -174,3 +174,28 @@ background-color: lightgray; color: gray; } + +.form-signin { + max-width: 600px; + padding: 15px; + margin: 0 auto; +} +.form-signin .form-signin-heading, +.form-signin .checkbox { + margin-bottom: 10px; +} +.form-signin .checkbox { + font-weight: normal; +} +.form-signin .form-control { + position: relative; + height: auto; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + padding: 10px; + font-size: 16px; +} +#id_payment_type_group .active { + background-color: lightgray; +} \ No newline at end of file
--- a/static/js/sat_website.js Tue Jan 27 08:07:15 2015 +0100 +++ b/static/js/sat_website.js Tue Jan 27 08:20:30 2015 +0100 @@ -5,6 +5,15 @@ $('#language_form').submit(); }); + // registration form + $('#id_subscription_amount').change(function() { + if ($(this).val() > 0) { + $('#id_payment_method_group').show(); + } else { + $('#id_payment_method_group').hide(); + } + }); + // open the big gallery when a thumbnail is clicked $('#carousel-screenshots .thumbnail').click(function() { $('#modal-screenshots').modal('show');
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/sat_website/adhesion_form.html Tue Jan 27 08:20:30 2015 +0100 @@ -0,0 +1,78 @@ +{% extends "sat_website/category.html" %} + +{% comment %} +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/>. +{% endcomment %} + +{% load i18n %} +{% load staticfiles %} +{% load utils %} + +{% block headline %}{% trans "Join the association" %}{% endblock %} +{% block main_container %} + +<form class="form-signin" action="adhesion_form" method="post"> + {% csrf_token %} + <fieldset> + <legend>{% trans "Please complete this form" %}</legend> + {% for section, fields in form.sections.items %} + <div class="form-group"> + {% if section %} + <label for="{{ fields.0.auto_id }}">{{ section }}</label> + {% endif %} + {% for field in fields %} + {% if field.field.widget|is_radio %} + <div class="text-center" id="{{ field.auto_id }}_group" name="{{ field.name }}_group"> + <span for="{{ field.auto_id }}">{{ field.label }}</span> + <div class="btn-group" data-toggle="buttons"> + {% for radio in field %} + <label for="{{ radio.id_for_label }}" class="btn btn-default{% if field.value == radio.choice_value %} active{% endif %}"> + {{ radio.tag }}{{ radio.choice_label }} + </label> + {% endfor %} + </div> + <div>{{ field.help_text }}</div> + </div> + {% elif field.field.widget|is_checkbox %} + <div class="checkbox"> + <label> + {{ field }}{{ field.label }} <span class="glyphicon glyphicon-asterisk"></span> + </label> + </div> + {% else %} + {% if field.field.required %} + <div class="input-group"> + {% endif %} + {{ field }} + {% if field.field.required %} + <span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span> + </div> + {% endif %} + {% endif %} + {% if field.errors %} + <div class="alert alert-danger" role="alert">{{ field.errors }}</div> + {% endif %} + {% endfor %} + </div> + {% endfor %} + </fieldset> + <button class="btn btn-lg btn-primary btn-block" type="submit">{% trans "Confirm" %}</button> +</form> + +{% endblock %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/sat_website/thank_you.html Tue Jan 27 08:20:30 2015 +0100 @@ -0,0 +1,56 @@ +{% extends "sat_website/category.html" %} + +{% comment %} +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/>. +{% endcomment %} + +{% load i18n %} +{% load staticfiles %} +{% load utils %} + +{% block headline %}{% trans "Thank you!" %}{% endblock %} +{% block main_container %} + +<p>{% trans "Your subscription has been registered." %}</p> + {% for section, fields in form.sections.items %} + <div class="form-group"> + {% for field in fields %} + {% if field.name == "payment_method" %} + {% if form.subscription_amount.value != "0" %} + <div>{{ field.label }}: {{ field|selected_label }}</div> + {% endif %} + {% elif field.name == "subscription_amount" %} + <div>{{ field.label }}: {{ field.value }} €</div> + {% elif field.name != "email_confirmation" and field.value %} + <div>{{ field.label }}: {{ field.value }}</div> + {% endif %} + {% endfor %} + </div> + {% endfor %} + </fieldset> +</form> + +{% if form.subscription_amount.value != "0" %} +<div class="alert alert-info" role="alert">{% blocktrans with amount=form.subscription_amount.value method=form.payment_method|selected_label %} +You chose to pay your annual subscription of {{ amount }} € via {{ method }}. You will receive during the next hours/days an email containing all the details (it is not automatised yet). +{% endblocktrans %} +</div> + +{% endif %} +{% endblock %}