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:
parent
a9efb44c01
commit
ef84cf85ba
@ -180,7 +180,6 @@ class CharField(Field):
|
|||||||
return {'maxlength': str(self.max_length)}
|
return {'maxlength': str(self.max_length)}
|
||||||
|
|
||||||
class IntegerField(Field):
|
class IntegerField(Field):
|
||||||
default_validators = [validators.validate_integer]
|
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
'invalid': _(u'Enter a whole number.'),
|
'invalid': _(u'Enter a whole number.'),
|
||||||
'max_value': _(u'Ensure this value is less than or equal to %s.'),
|
'max_value': _(u'Ensure this value is less than or equal to %s.'),
|
||||||
|
@ -247,6 +247,20 @@ class BaseForm(StrAndUnicode):
|
|||||||
self._errors[name] = self.error_class(e.messages)
|
self._errors[name] = self.error_class(e.messages)
|
||||||
if name in self.cleaned_data:
|
if name in self.cleaned_data:
|
||||||
del self.cleaned_data[name]
|
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:
|
try:
|
||||||
self.cleaned_data = self.clean()
|
self.cleaned_data = self.clean()
|
||||||
except ValidationError, e:
|
except ValidationError, e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user