1
0
mirror of https://github.com/django/django.git synced 2025-07-07 11:19:12 +00:00

[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
This commit is contained in:
Honza Král 2009-06-03 02:38:39 +00:00
parent a9efb44c01
commit ef84cf85ba
2 changed files with 14 additions and 1 deletions

View File

@ -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.'),

View File

@ -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: