mirror of
https://github.com/django/django.git
synced 2025-07-07 11:19:12 +00:00
[soc2009/model-validation] Moved execution of validators to separate method
This method (run_validators) is being run after the validate() method finishes and doesn't produce any errors. Errors from individual validators are aggregated and then raised together in one ValidationError. git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10947 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
6d840d9b05
commit
c43edf6d76
@ -119,12 +119,19 @@ class Field(object):
|
||||
def validate(self, value):
|
||||
if value in EMPTY_VALUES and self.required:
|
||||
raise ValidationError(self.error_messages['required'])
|
||||
|
||||
def run_validators(self, value):
|
||||
errors = []
|
||||
for v in self.validators:
|
||||
# don't run complex validators since they need all_values
|
||||
# and must therefore be run on the form level
|
||||
if not isinstance(v, validators.ComplexValidator):
|
||||
try:
|
||||
v(value)
|
||||
|
||||
except ValidationError, e:
|
||||
errors.extend(e.messages)
|
||||
if errors:
|
||||
raise ValidationError(errors)
|
||||
|
||||
def clean(self, value):
|
||||
"""
|
||||
@ -135,6 +142,7 @@ class Field(object):
|
||||
"""
|
||||
value = self.to_python(value)
|
||||
self.validate(value)
|
||||
self.run_validators(value)
|
||||
return value
|
||||
|
||||
def widget_attrs(self, widget):
|
||||
|
Loading…
x
Reference in New Issue
Block a user