From ef84cf85ba98ab4b3b62018a2404b67cd3daf5a4 Mon Sep 17 00:00:00 2001 From: Honza Král Date: Wed, 3 Jun 2009 02:38:39 +0000 Subject: [soc2009/model-validation] Added code for calling validators on form fields git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10909 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/forms/forms.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'django/forms/forms.py') diff --git a/django/forms/forms.py b/django/forms/forms.py index 6b6f1c5971..b5c0fc06e0 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -247,6 +247,20 @@ class BaseForm(StrAndUnicode): self._errors[name] = self.error_class(e.messages) if name in self.cleaned_data: del self.cleaned_data[name] + + # run all the validators after the fields have been cleaned since they + # need access to all_values + for name, field in self.fields.items(): + if not name in self.cleaned_data: + continue + for v in field.validators: + try: + v(self.cleaned_data[name], all_values=self.cleaned_data) + except ValidationError, e: + self._errors.setdefault(name, self.error_class()).extend(e.messages) + if name in self.cleaned_data: + del self.cleaned_data[name] + try: self.cleaned_data = self.clean() except ValidationError, e: -- cgit v1.3