Changeset 6067
- Timestamp:
- 09/08/07 14:24:46 (1 year ago)
- Files:
-
- django/trunk/django/core/validators.py (modified) (1 diff)
- django/trunk/django/newforms/fields.py (modified) (1 diff)
- django/trunk/tests/regressiontests/forms/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/validators.py
r5895 r6067 424 424 raise ValidationError, _("Please enter a valid decimal number.") 425 425 426 pieces = str(val). split('.')426 pieces = str(val).lstrip("-").split('.') 427 427 decimals = (len(pieces) == 2) and len(pieces[1]) or 0 428 428 digits = len(pieces[0]) django/trunk/django/newforms/fields.py
r5861 r6067 191 191 except DecimalException: 192 192 raise ValidationError(ugettext('Enter a number.')) 193 pieces = str(value). split('.')193 pieces = str(value).lstrip("-").split('.') 194 194 decimals = (len(pieces) == 2) and len(pieces[1]) or 0 195 195 digits = len(pieces[0]) django/trunk/tests/regressiontests/forms/tests.py
r5876 r6067 1168 1168 ... 1169 1169 ValidationError: [u'Ensure that there are no more than 2 digits before the decimal point.'] 1170 >>> f.clean('-12.34') 1171 Decimal("-12.34") 1172 >>> f.clean('-123.45') 1173 Traceback (most recent call last): 1174 ... 1175 ValidationError: [u'Ensure that there are no more than 4 digits in total.'] 1176 >>> f.clean('-.12') 1177 Decimal("-0.12") 1178 >>> f.clean('-00.12') 1179 Decimal("-0.12") 1180 >>> f.clean('-000.12') 1181 Decimal("-0.12") 1182 >>> f.clean('-000.123') 1183 Traceback (most recent call last): 1184 ... 1185 ValidationError: [u'Ensure that there are no more than 2 decimal places.'] 1186 >>> f.clean('-000.1234') 1187 Traceback (most recent call last): 1188 ... 1189 ValidationError: [u'Ensure that there are no more than 4 digits in total.'] 1190 >>> f.clean('--0.12') 1191 Traceback (most recent call last): 1192 ... 1193 ValidationError: [u'Enter a number.'] 1194 1170 1195 >>> f = DecimalField(max_digits=4, decimal_places=2, required=False) 1171 1196 >>> f.clean('')
