# HG changeset patch # User souliane # Date 1422343230 -3600 # Node ID 9d553570cc611ba821a8fd38419afd46fb06b762 # Parent 73c6333fd124a2ad176d0faad84a759487bb3bbf add adhesion_form.html and thank_you.html diff -r 73c6333fd124 -r 9d553570cc61 sat_website/forms.py --- /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 . +""" + +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 diff -r 73c6333fd124 -r 9d553570cc61 sat_website/templatetags/utils.py --- 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. diff -r 73c6333fd124 -r 9d553570cc61 sat_website/views.py --- 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 diff -r 73c6333fd124 -r 9d553570cc61 static/css/sat_website.css --- 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 diff -r 73c6333fd124 -r 9d553570cc61 static/js/sat_website.js --- 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'); diff -r 73c6333fd124 -r 9d553570cc61 templates/sat_website/adhesion_form.html --- /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 . +{% endcomment %} + +{% load i18n %} +{% load staticfiles %} +{% load utils %} + +{% block headline %}{% trans "Join the association" %}{% endblock %} +{% block main_container %} + + + +{% endblock %} diff -r 73c6333fd124 -r 9d553570cc61 templates/sat_website/thank_you.html --- /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 . +{% endcomment %} + +{% load i18n %} +{% load staticfiles %} +{% load utils %} + +{% block headline %}{% trans "Thank you!" %}{% endblock %} +{% block main_container %} + +

{% trans "Your subscription has been registered." %}

+ {% for section, fields in form.sections.items %} +
+ {% for field in fields %} + {% if field.name == "payment_method" %} + {% if form.subscription_amount.value != "0" %} +
{{ field.label }}: {{ field|selected_label }}
+ {% endif %} + {% elif field.name == "subscription_amount" %} +
{{ field.label }}: {{ field.value }} €
+ {% elif field.name != "email_confirmation" and field.value %} +
{{ field.label }}: {{ field.value }}
+ {% endif %} + {% endfor %} +
+ {% endfor %} + + + +{% if form.subscription_amount.value != "0" %} + + +{% endif %} +{% endblock %}