1
0
mirror of https://github.com/django/django.git synced 2025-07-07 19:29:12 +00:00

[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
This commit is contained in:
Honza Král 2009-06-03 02:38:06 +00:00
parent 7506471585
commit 92934650f6

View File

@ -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:
@ -712,6 +713,9 @@ class TypedChoiceField(ChoiceField):
raise ValidationError(self.error_messages['invalid_choice'] % {'value': value})
return value
def validate(self, value):
pass
class MultipleChoiceField(ChoiceField):
hidden_widget = MultipleHiddenInput
widget = SelectMultiple
@ -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):
"""