summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-06-08 00:55:27 +0000
committerHonza Král <honza.kral@gmail.com>2009-06-08 00:55:27 +0000
commitc43edf6d768f0ad001a6fea73084c04428f9721e (patch)
treed16f1d5849e6581a072ab5c21ac44e79354a75de
parent6d840d9b05f62a4eded37c6cc2da624a41d92e07 (diff)
[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
-rw-r--r--django/forms/fields.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index d65edd7047..6adc6dba2a 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -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):
- v(value)
-
+ 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):