Author: Honza_Kral
Date: 2009-06-02 21:36:49 -0500 (Tue, 02 Jun 2009)
New Revision: 10901
Modified:
django/branches/soc2009/model-validation/django/forms/fields.py
Log:
[soc2009/model-validation] IntegerField 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:36:33 UTC (rev 10900)
+++ django/branches/soc2009/model-validation/django/forms/fields.py
2009-06-03 02:36:49 UTC (rev 10901)
@@ -191,23 +191,27 @@
self.max_value, self.min_value = max_value, min_value
super(IntegerField, self).__init__(*args, **kwargs)
- def clean(self, value):
+ def to_python(self, value):
"""
Validates that int() can be called on the input. Returns the result
of int(). Returns None for empty values.
"""
- super(IntegerField, self).clean(value)
+ value = super(IntegerField, self).to_python(value)
if value in EMPTY_VALUES:
return None
+
try:
value = int(str(value))
except (ValueError, TypeError):
raise ValidationError(self.error_messages['invalid'])
+ return value
+
+ def validate(self, value):
+ super(IntegerField, self).validate(value)
if self.max_value is not None and value > self.max_value:
raise ValidationError(self.error_messages['max_value'] %
self.max_value)
if self.min_value is not None and value < self.min_value:
raise ValidationError(self.error_messages['min_value'] %
self.min_value)
- return value
class FloatField(Field):
default_error_messages = {
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---