mirror of
https://github.com/django/django.git
synced 2025-07-07 11:19:12 +00:00
[soc2009/model-validation] IntegerField migrated to split to_python/validate
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10901 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
45af711718
commit
e33029cca3
@ -191,23 +191,27 @@ class IntegerField(Field):
|
|||||||
self.max_value, self.min_value = max_value, min_value
|
self.max_value, self.min_value = max_value, min_value
|
||||||
super(IntegerField, self).__init__(*args, **kwargs)
|
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
|
Validates that int() can be called on the input. Returns the result
|
||||||
of int(). Returns None for empty values.
|
of int(). Returns None for empty values.
|
||||||
"""
|
"""
|
||||||
super(IntegerField, self).clean(value)
|
value = super(IntegerField, self).to_python(value)
|
||||||
if value in EMPTY_VALUES:
|
if value in EMPTY_VALUES:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
value = int(str(value))
|
value = int(str(value))
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
raise ValidationError(self.error_messages['invalid'])
|
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:
|
if self.max_value is not None and value > self.max_value:
|
||||||
raise ValidationError(self.error_messages['max_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:
|
if self.min_value is not None and value < self.min_value:
|
||||||
raise ValidationError(self.error_messages['min_value'] % self.min_value)
|
raise ValidationError(self.error_messages['min_value'] % self.min_value)
|
||||||
return value
|
|
||||||
|
|
||||||
class FloatField(Field):
|
class FloatField(Field):
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user