Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bug on expedition address fields solved;

  • Loading branch information...
commit 4fe9afe3748af64d1c622e748f0999e3dc56a911 1 parent df2a4ef
@guglielmo guglielmo authored
View
23 forms.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+from os import sys
from django import forms
from op_associazione.models import Membership, Citizen, Politician, Organization, Associate
@@ -27,7 +28,28 @@ def clean(self):
class AssociateForm(forms.ModelForm):
accept_policy = forms.BooleanField(help_text='Approvazione statuto')
accept_privacy_policy = forms.BooleanField(help_text='Approvazione trattamento dati personali')
+ exp_address_provided = forms.BooleanField(required=False)
+ exp_street = forms.CharField(label='Via, viale, ecc', required=False)
+ exp_civic_nb = forms.CharField(label='Numero civico', required=False)
+ exp_zip_code = forms.CharField(label='CAP', required=False)
+ exp_location = forms.CharField(label='Città', required=False)
+ exp_province = forms.CharField(label='Provincia', required=False)
+ exp_country = forms.CharField(label='Nazione', required=False)
+
+ def clean(self):
+ """custom validation for expedition address, only if different from main address"""
+ cleaned_data = super(AssociateForm, self).clean()
+ exp_address_provided = cleaned_data.get('exp_address_provided')
+ if exp_address_provided:
+ for f in ['street', 'civic_nb', 'zip_code', 'location', 'province', 'country']:
+ field = "exp_%s" % (f,)
+ if cleaned_data.get(field) == '':
+ self._errors[field] = self.error_class(["Questo campo è obbligatorio."])
+ del cleaned_data[field]
+
+ return cleaned_data
+
def clean_fiscal_code(self):
import re
cc = self.cleaned_data.get('fiscal_code').upper().replace(' ', '')
@@ -41,6 +63,7 @@ def clean_fiscal_code(self):
class Meta():
widgets = {
+ 'gender': forms.Select(attrs={'class': 'span1'}),
'notes': forms.Textarea(attrs={'cols': 30, 'rows': 10}),
'charge': forms.Textarea(attrs={'cols': 30, 'rows': 10}),
'birth_date': forms.DateInput(format='%d/%m/%Y', attrs={'class':'datepicker span2'}),
View
2  models.py
@@ -57,7 +57,7 @@ class Associate(models.Model):
birth_date = models.DateField('Data di nascita')
gender = models.CharField('Sesso',max_length=1, choices=GENDERS, null=False, blank=False)
fiscal_code = models.CharField('Codice fiscale',max_length=20, help_text="Inserisci codice fiscale (16 caratteri)")
- phone_number = models.CharField('Telefono',max_length=200,blank=True, null=True)
+ phone_number = models.CharField('Telefono',max_length=200)
wants_newsletter = models.BooleanField('Newsletter',help_text='Voglio ricevere la newsletter via email')
email = models.EmailField(unique=True)
street = models.CharField('Via, viale, ecc', max_length=200)
View
42 templates/subscribe/associate_form.html
@@ -33,7 +33,10 @@
<div class="control-group {% if membership_form.fee.errors %}error{% endif %}">
<label for="id_{{ membership_form.fee.html_name }}">*{{ membership_form.fee.label }}</label>
- {{ membership_form.fee }}
+ <span class="input-append">
+ {{ membership_form.fee }}
+ <span class="add-on">,00</span>
+ </span>
<span class="help-inline">
{% if membership_form.fee.errors %}
{% for error in membership_form.fee.errors %}
@@ -211,13 +214,21 @@
Indirizzo di spedizione della tessera
</legend>
+ <div class="control-group {% if associate_form.exp_address_provided.errors %}error{% endif %}">
+ <label class="checkbox">
+ {{ associate_form.exp_address_provided }}
+ <div>E' diverso dall'indirizzo di residenza</div>
+ </label>
+ <span class="help-inline">
+ {% if associate_form.exp_address_provided.errors %}
+ {% for error in associate_form.exp_address_provided.errors %}
+ {{ error|escape }}
+ {% endfor %}
+ {% endif %}
+ </span>
+ </div>
- <label class="checkbox">
- <input type="checkbox" name="expedition_address_provided" id="address-box"{% if expedition_address_provided %}checked="yes"{% endif %} />
- E' diverso dall'indirizzo di residenza
- </label>
-
- <div id="hiddenField" {% if not expedition_address_provided %}style="display:none;"{% endif %}>
+ <div id="hiddenField" {% if not associate_form.exp_address_provided.value %}style="display:none;"{% endif %}>
<div class="control-group {% if associate_form.exp_street.errors %}error{% endif %}">
<label for="id_{{ associate_form.exp_street.html_name }}">*{{ associate_form.exp_street.label }}</label>
@@ -397,6 +408,9 @@
padding: 1em;
margin-bottom: 2em;
}
+ #id_fee {
+ text-align: right;
+ }
</style>
{% endblock %}
@@ -438,10 +452,20 @@
yearRange: "1900:+0"
});
- $( '#address-box' ).click(function() {
+ $( '#id_exp_address_provided' ).click(function() {
$('#hiddenField').slideToggle();
+ if (!$(this).attr('checked')) {
+ // reset fields when unchecking
+ $('#id_exp_street').val("");
+ $('#id_exp_civic_nb').val("");
+ $('#id_exp_zip_code').val("");
+ $('#id_exp_location').val("");
+ $('#id_exp_province').val("");
+ $('#id_exp_country').val("");
+ };
});
-
+
+
});
</script>
{% endblock %}
View
14 templates/subscribe/renewal.html
@@ -38,7 +38,10 @@
<div class="control-group {% if form.fee.errors %}error{% endif %}">
<label for="id_{{ form.fee.html_name }}">*{{ form.fee.label }}</label>
- {{ form.fee }}
+ <span class="input-append">
+ {{ form.fee }}
+ <span class="add-on">,00</span>
+ </span>
<span class="help-inline">
{% if form.fee.errors %}
{% for error in form.fee.errors %}
@@ -69,3 +72,12 @@
</div>
{% endblock %}
+
+{% block css_styles %}
+ {{ block.super }}
+ <style>
+ #id_fee {
+ text-align: right;
+ }
+ </style>
+{% endblock %}
View
3  views.py
@@ -94,7 +94,7 @@ def check_expedition_address(provided, form):
def subscribe_module(request, member_type):
associate_form = build_associate_form(request,member_type)
membership_form = build_membership_form(request,member_type=member_type)
- exp_address_provided = request.POST.get('expedition_address_provided', False)
+ exp_address_provided = request.POST.get('exp_address_provided', False)
if request.method == 'POST': # If the form has been submitted...
if associate_form.is_valid() & membership_form.is_valid(): # All validation rules pass
@@ -128,7 +128,6 @@ def subscribe_module(request, member_type):
return render_to_response('subscribe/'+ member_type +'_form.html', {
'associate_form' : associate_form,
'membership_form' : membership_form,
- 'expedition_address_provided' : exp_address_provided,
'member_type' : member_type
}, context_instance=RequestContext(request))
Please sign in to comment.
Something went wrong with that request. Please try again.