Author: Honza_Kral
Date: 2009-06-02 21:38:06 -0500 (Tue, 02 Jun 2009)
New Revision: 10907
Modified:
django/branches/soc2009/model-validation/django/forms/fields.py
Log:
[soc2009/model-validation] More fields migrated to split to_python/validate
Modified: django/branches/soc2009/model-validation/django/forms/fields.py
===================================================================
--- django/branches/soc2009/model-validation/django/forms/fields.py
2009-06-03 02:37:51 UTC (rev 10906)
+++ django/branches/soc2009/model-validation/django/forms/fields.py
2009-06-03 02:38:06 UTC (rev 10907)
@@ -698,12 +698,13 @@
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 @@
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 @@
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,8 +833,11 @@
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):
"""
Returns a single value for the given list of values. The values can be
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---