summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-06-03 02:38:06 +0000
committerHonza Král <honza.kral@gmail.com>2009-06-03 02:38:06 +0000
commit92934650f6cf428e7b7bf796db138c5a46370578 (patch)
tree437ae3703fe2c94abe5319f1243bf1d56ea0169f
parent7506471585719ba727de0f650b45e59cfaa4f001 (diff)
[soc2009/model-validation] More fields migrated to split to_python/validate
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10907 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/forms/fields.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 90eb9c5c4a..625c74235b 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -698,12 +698,13 @@ class TypedChoiceField(ChoiceField):
self.empty_value = kwargs.pop('empty_value', '')
super(TypedChoiceField, self).__init__(*args, **kwargs)
- def clean(self, value):
+ def to_python(self, value):
"""
Validate that the value is in self.choices and can be coerced to the
right type.
"""
- value = super(TypedChoiceField, self).clean(value)
+ value = super(TypedChoiceField, self).to_python(value)
+ super(TypedChoiceField, self).validate(value)
if value == self.empty_value or value in EMPTY_VALUES:
return self.empty_value
try:
@@ -711,6 +712,9 @@ class TypedChoiceField(ChoiceField):
except (ValueError, TypeError, ValidationError):
raise ValidationError(self.error_messages['invalid_choice'] % {'value': value})
return value
+
+ def validate(self, value):
+ pass
class MultipleChoiceField(ChoiceField):
hidden_widget = MultipleHiddenInput
@@ -791,6 +795,9 @@ class MultiValueField(Field):
f.required = False
self.fields = fields
+ def validate(self, value):
+ pass
+
def clean(self, value):
"""
Validates every value in the given list. A value is validated against
@@ -826,7 +833,10 @@ class MultiValueField(Field):
errors.extend(e.messages)
if errors:
raise ValidationError(errors)
- return self.compress(clean_data)
+
+ out = self.compress(clean_data)
+ self.validate(out)
+ return out
def compress(self, data_list):
"""