From 46cc54310a0cbac2d6da4a4a7c7d4ed07b78eac8 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 11 Feb 2011 01:11:44 +0100 Subject: Prevent from adding the same parcel twice (closes #160) --- ishtar/furnitures/forms.py | 17 +---------------- 1 file changed, 1 insertion(+), 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) -- cgit v1.2.3