From 92934650f6cf428e7b7bf796db138c5a46370578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Wed, 3 Jun 2009 02:38:06 +0000 Subject: [PATCH] [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 --- django/forms/fields.py | 16 +++++++++++++--- 1 file 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): """