diff options
Diffstat (limited to 'ishtar/furnitures/forms.py')
| -rw-r--r-- | ishtar/furnitures/forms.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index e771fe595..12c9ae9c0 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -26,7 +26,7 @@ from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ from django.template import Context, RequestContext from django.shortcuts import render_to_response -from django.forms.formsets import formset_factory +from django.forms.formsets import formset_factory, BaseFormSet from django import forms from formwizard.forms import NamedUrlSessionFormWizard @@ -43,6 +43,9 @@ class FinalForm(forms.Form): final = True form_label = _("Confirm") +class FormSet(BaseFormSet): + pass + class Wizard(NamedUrlSessionFormWizard): def get_template(self, request, storage): templates = ['default_wizard.html'] @@ -230,7 +233,22 @@ class TownForm(forms.Form): 'autocomplete-town', associated_model=models.Town), validators=[models.Town.valid_id], required=False) -TownFormSet = formset_factory(TownForm, can_delete=True) +class TownFormSet(FormSet): + def clean(self): + """Checks that no towns are duplicated.""" + if any(self.errors): + return + towns = [] + for i in range(0, self.total_form_count()): + form = self.forms[i] + if 'town' not in form.cleaned_data: + continue + town = form.cleaned_data['town'] + if town in towns: + raise forms.ValidationError, _("There are identical towns.") + towns.append(town) + +TownFormSet = formset_factory(TownForm, can_delete=True, formset=TownFormSet) TownFormSet.form_label = _("Towns") class FileForm3(forms.Form): |
