diff options
| author | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-01-07 00:51:24 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-01-07 00:51:24 +0100 | 
| commit | ac07856860b811d27e5cd4265cf85a2523f87a41 (patch) | |
| tree | aff390f551a1ef0fd6322a5f5324a70cde2ae6e3 | |
| parent | 693469193a93c4569472c7aabb9e5565825f62ad (diff) | |
| download | Ishtar-ac07856860b811d27e5cd4265cf85a2523f87a41.tar.bz2 Ishtar-ac07856860b811d27e5cd4265cf85a2523f87a41.zip | |
Test unicity of parcels (refs #14)
| -rw-r--r-- | ishtar/furnitures/forms.py | 24 | 
1 files changed, 19 insertions, 5 deletions
| diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index 6723b99a6..1dc06fb32 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -282,11 +282,6 @@ class TownFormSet(FormSet):  TownFormSet = formset_factory(TownForm, can_delete=True, formset=TownFormSet)  TownFormSet.form_label = _("Towns") -class ParcelFormSet(FormSet): -    def __init__(self, *args, **kwargs): -        super(FormSet, self).__init__(*args, **kwargs) - -  class ParcelForm(forms.Form):      form_label = _("Parcels")      town = forms.ChoiceField(label=_("Town"), choices=(), @@ -312,6 +307,25 @@ class ParcelForm(forms.Form):          if towns:              self.fields['town'].choices = [('', '--')] + towns +class ParcelFormSet(FormSet): +    def clean(self): +        """Checks that no parcels are duplicated.""" +        if any(self.errors): +            return +        parcels = [] +        for i in range(0, self.total_form_count()): +            form = self.forms[i] +            if not hasattr(form, 'cleaned_data')\ +               or 'town' not in form.cleaned_data \ +               or 'section' not in form.cleaned_data \ +               or 'parcel_number' not in form.cleaned_data: +                continue +            parcel = (form.cleaned_data['town'], form.cleaned_data['section'], +                       form.cleaned_data['parcel_number']) +            if parcel in parcels: +                raise forms.ValidationError, _("There are identical parcels.") +            parcels.append(parcel) +  ParcelFormSet = formset_factory(ParcelForm, can_delete=True,                                  formset=ParcelFormSet)  ParcelFormSet.form_label = _("Parcels") | 
