Match IntegerField validation with Django's, preventing decimal values being stored as ints, fixes #2835.

Match IntegerField validation with Django IntegerField, prevents decimal values being stored as ints, fixes #2835
 On branch master
This commit is contained in:
Ryan Allen 2015-04-17 14:38:35 -04:00
parent ecb37f518e
commit 1f10a39d31
2 changed files with 6 additions and 3 deletions

View File

@ -682,7 +682,7 @@ class IntegerField(Field):
self.fail('max_string_length')
try:
data = int(data)
data = int(re.compile(r'\.0*\s*$').sub('', str(data)))
except (ValueError, TypeError):
self.fail('invalid')
return data

View File

@ -549,10 +549,13 @@ class TestIntegerField(FieldValues):
1: 1,
0: 0,
1.0: 1,
0.0: 0
0.0: 0,
'1.0': 1
}
invalid_inputs = {
'abc': ['A valid integer is required.']
0.5: ['A valid integer is required.'],
'abc': ['A valid integer is required.'],
'0.5': ['A valid integer is required.']
}
outputs = {
'1': 1,