diff options
| author | Honza Král <honza.kral@gmail.com> | 2009-06-03 02:38:39 +0000 |
|---|---|---|
| committer | Honza Král <honza.kral@gmail.com> | 2009-06-03 02:38:39 +0000 |
| commit | ef84cf85ba98ab4b3b62018a2404b67cd3daf5a4 (patch) | |
| tree | d52ae96f6886da6917c671de1fc9a1c5cb69a177 /django/forms/forms.py | |
| parent | a9efb44c0159e0ea7a6f0040e2185d335c25f799 (diff) | |
[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
Diffstat (limited to 'django/forms/forms.py')
| -rw-r--r-- | django/forms/forms.py | 14 |
1 files changed, 14 insertions, 0 deletions
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: |
