From 63f244f14413e0981c76dda8bf6f76e7b9df3d2a Mon Sep 17 00:00:00 2001 From: Honza Král Date: Sun, 5 Jul 2009 13:26:57 +0000 Subject: [soc2009/model-validation] Make sure that all validators in the same group (simple/complex) get run even if they all fail and we get all their messages. git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11185 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/forms/forms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'django') diff --git a/django/forms/forms.py b/django/forms/forms.py index bb5b086d05..c7f07657d4 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -254,6 +254,7 @@ class BaseForm(StrAndUnicode): for name, field in self.fields.items(): if not name in self.cleaned_data: continue + failed = False for v in field.validators: # skip noncomplex validators, they have already been run on the Field if not isinstance(v, ComplexValidator): @@ -261,14 +262,14 @@ class BaseForm(StrAndUnicode): try: v(self.cleaned_data[name], all_values=self.cleaned_data) except ValidationError, e: + failed = True error_list = self._errors.setdefault(name, self.error_class()) if hasattr(e, 'code'): error_list.append(field.error_messages.get(e.code, e.messages[0])) else: error_list.extend(e.messages) - if name in self.cleaned_data: - del self.cleaned_data[name] - + if failed: + del self.cleaned_data[name] try: self.cleaned_data = self.clean() except ValidationError, e: -- cgit v1.3