summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-02-11 01:11:44 +0100
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-02-11 01:11:44 +0100
commit107463ea683b02c90a090fab65c8803383b9596a (patch)
treebd3d2aa66f7ca10dfc0fe74675c482d3bc7a1407
parentcfb18b8ba86967121d4ec552b410f346441ae8d6 (diff)
downloadIshtar-107463ea683b02c90a090fab65c8803383b9596a.tar.bz2
Ishtar-107463ea683b02c90a090fab65c8803383b9596a.zip
Prevent from adding the same parcel twice (closes #160)
-rw-r--r--ishtar/furnitures/forms.py17
1 files changed, 1 insertions, 16 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py
index e99d4f077..68c672c01 100644
--- a/ishtar/furnitures/forms.py
+++ b/ishtar/furnitures/forms.py
@@ -858,22 +858,7 @@ class ParcelForm(forms.Form):
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 not 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)
+ return clean_duplicated(self, ('town', 'parcel_number', 'year'))
ParcelFormSet = formset_factory(ParcelForm, can_delete=True,
formset=ParcelFormSet)