Ticket #7333: 7333-suggestion.diff
File 7333-suggestion.diff, 3.2 KB (added by , 16 years ago) |
---|
-
django/newforms/fields.py
216 216 'max_value': _(u'Ensure this value is less than or equal to %s.'), 217 217 'min_value': _(u'Ensure this value is greater than or equal to %s.'), 218 218 'max_digits': _('Ensure that there are no more than %s digits in total.'), 219 ' max_decimal_places': _('Ensure that there are no more than %s decimal places.'),220 ' max_whole_digits': _('Ensure that there are no more than %s digits before the decimal point.')219 'decimal_places': _('Ensure that there are no more than %s decimal places.'), 220 'total_digits': _('Ensure that there are no more than %s digits before the decimal point.') 221 221 } 222 222 223 223 def __init__(self, max_value=None, min_value=None, max_digits=None, decimal_places=None, *args, **kwargs): … … 250 250 if self.max_digits is not None and (digits + decimals) > self.max_digits: 251 251 raise ValidationError(self.error_messages['max_digits'] % self.max_digits) 252 252 if self.decimal_places is not None and decimals > self.decimal_places: 253 raise ValidationError(self.error_messages[' max_decimal_places'] % self.decimal_places)253 raise ValidationError(self.error_messages['decimal_places'] % self.decimal_places) 254 254 if self.max_digits is not None and self.decimal_places is not None and digits > (self.max_digits - self.decimal_places): 255 raise ValidationError(self.error_messages[' max_whole_digits'] % (self.max_digits - self.decimal_places))255 raise ValidationError(self.error_messages['total_digits'] % (self.max_digits - self.decimal_places)) 256 256 return value 257 257 258 258 DEFAULT_DATE_INPUT_FORMATS = ( -
tests/regressiontests/forms/error_messages.py
77 77 >>> e['min_value'] = 'MIN VALUE IS %s' 78 78 >>> e['max_value'] = 'MAX VALUE IS %s' 79 79 >>> e['max_digits'] = 'MAX DIGITS IS %s' 80 >>> e[' max_decimal_places'] = 'MAX DP IS %s'81 >>> e[' max_whole_digits'] = 'MAX DIGITS BEFORE DP IS %s'80 >>> e['decimal_places'] = 'MAX DP IS %s' 81 >>> e['total_digits'] = 'MAX DIGITS BEFORE DP IS %s' 82 82 >>> f = DecimalField(min_value=5, max_value=10, error_messages=e) 83 83 >>> f2 = DecimalField(max_digits=4, decimal_places=2, error_messages=e) 84 84 >>> f.clean('') -
docs/newforms.txt
1295 1295 * Validates that the given value is a decimal. Leading and trailing 1296 1296 whitespace is ignored. 1297 1297 * Error message keys: ``required``, ``invalid``, ``max_value``, 1298 ``min_value``, ``max_digits``, ``max_decimal_places``, 1299 ``max_whole_digits`` 1298 ``min_value``, ``max_digits``, ``decimal_places``, ``total_digits`` 1300 1299 1301 1300 Takes four optional arguments: ``max_value``, ``min_value``, ``max_digits``, 1302 1301 and ``decimal_places``. The first two define the limits for the fields value.