Ticket #7333: 7333-suggestion.diff

File 7333-suggestion.diff, 3.2 KB (added by Joshua Uziel, 16 years ago)

A suggested fix to the issue.

  • django/newforms/fields.py

     
    216216        'max_value': _(u'Ensure this value is less than or equal to %s.'),
    217217        'min_value': _(u'Ensure this value is greater than or equal to %s.'),
    218218        '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.')
    221221    }
    222222
    223223    def __init__(self, max_value=None, min_value=None, max_digits=None, decimal_places=None, *args, **kwargs):
     
    250250        if self.max_digits is not None and (digits + decimals) > self.max_digits:
    251251            raise ValidationError(self.error_messages['max_digits'] % self.max_digits)
    252252        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)
    254254        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))
    256256        return value
    257257
    258258DEFAULT_DATE_INPUT_FORMATS = (
  • tests/regressiontests/forms/error_messages.py

     
    7777>>> e['min_value'] = 'MIN VALUE IS %s'
    7878>>> e['max_value'] = 'MAX VALUE IS %s'
    7979>>> 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'
    8282>>> f = DecimalField(min_value=5, max_value=10, error_messages=e)
    8383>>> f2 = DecimalField(max_digits=4, decimal_places=2, error_messages=e)
    8484>>> f.clean('')
  • docs/newforms.txt

     
    12951295    * Validates that the given value is a decimal. Leading and trailing
    12961296      whitespace is ignored.
    12971297    * 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``
    13001299
    13011300Takes four optional arguments: ``max_value``, ``min_value``, ``max_digits``,
    13021301and ``decimal_places``. The first two define the limits for the fields value.
Back to Top