Ticket #8290: 8290_decimal_field_clean.diff
File 8290_decimal_field_clean.diff, 1.4 KB (added by , 16 years ago) |
---|
-
django/forms/fields.py
244 244 value = Decimal(value) 245 245 except DecimalException: 246 246 raise ValidationError(self.error_messages['invalid']) 247 pieces = str(value).lstrip("-").split('.')248 decimals = (len(pieces) == 2) and len(pieces[1]) or 0249 digits = len(pieces[0])247 sign, digittuple, exponent = value.as_tuple() 248 decimals = exponent * -1 249 digits = (len(digittuple) - decimals) or 1 250 250 if self.max_value is not None and value > self.max_value: 251 251 raise ValidationError(self.error_messages['max_value'] % self.max_value) 252 252 if self.min_value is not None and value < self.min_value: -
tests/regressiontests/forms/fields.py
403 403 >>> f.clean('00.50') == Decimal("0.50") 404 404 True 405 405 406 >>> f = DecimalField(decimal_places=2) 407 >>> f.clean('0.00000001') 408 Traceback (most recent call last): 409 ... 410 ValidationError: [u'Ensure that there are no more than 2 decimal places.'] 411 406 412 # DateField ################################################################### 407 413 408 414 >>> import datetime