summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-06-03 02:38:39 +0000
committerHonza Král <honza.kral@gmail.com>2009-06-03 02:38:39 +0000
commitef84cf85ba98ab4b3b62018a2404b67cd3daf5a4 (patch)
treed52ae96f6886da6917c671de1fc9a1c5cb69a177 /django
parenta9efb44c0159e0ea7a6f0040e2185d335c25f799 (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')
-rw-r--r--django/forms/fields.py1
-rw-r--r--django/forms/forms.py14
2 files changed, 14 insertions, 1 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index cf1daa0003..9446ed2eea 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -180,7 +180,6 @@ class CharField(Field):
return {'maxlength': str(self.max_length)}
class IntegerField(Field):
- default_validators = [validators.validate_integer]
default_error_messages = {
'invalid': _(u'Enter a whole number.'),
'max_value': _(u'Ensure this value is less than or equal to %s.'),
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: