Code

Ticket #7333: 7333-suggestion.diff

File 7333-suggestion.diff, 3.2 KB (added by uzi, 6 years ago)

A suggested fix to the issue.

Line 
1Index: django/newforms/fields.py
2===================================================================
3--- django/newforms/fields.py   (revision 7948)
4+++ django/newforms/fields.py   (working copy)
5@@ -216,8 +216,8 @@
6         'max_value': _(u'Ensure this value is less than or equal to %s.'),
7         'min_value': _(u'Ensure this value is greater than or equal to %s.'),
8         'max_digits': _('Ensure that there are no more than %s digits in total.'),
9-        'max_decimal_places': _('Ensure that there are no more than %s decimal places.'),
10-        'max_whole_digits': _('Ensure that there are no more than %s digits before the decimal point.')
11+        'decimal_places': _('Ensure that there are no more than %s decimal places.'),
12+        'total_digits': _('Ensure that there are no more than %s digits before the decimal point.')
13     }
14 
15     def __init__(self, max_value=None, min_value=None, max_digits=None, decimal_places=None, *args, **kwargs):
16@@ -250,9 +250,9 @@
17         if self.max_digits is not None and (digits + decimals) > self.max_digits:
18             raise ValidationError(self.error_messages['max_digits'] % self.max_digits)
19         if self.decimal_places is not None and decimals > self.decimal_places:
20-            raise ValidationError(self.error_messages['max_decimal_places'] % self.decimal_places)
21+            raise ValidationError(self.error_messages['decimal_places'] % self.decimal_places)
22         if self.max_digits is not None and self.decimal_places is not None and digits > (self.max_digits - self.decimal_places):
23-            raise ValidationError(self.error_messages['max_whole_digits'] % (self.max_digits - self.decimal_places))
24+            raise ValidationError(self.error_messages['total_digits'] % (self.max_digits - self.decimal_places))
25         return value
26 
27 DEFAULT_DATE_INPUT_FORMATS = (
28Index: tests/regressiontests/forms/error_messages.py
29===================================================================
30--- tests/regressiontests/forms/error_messages.py       (revision 7948)
31+++ tests/regressiontests/forms/error_messages.py       (working copy)
32@@ -77,8 +77,8 @@
33 >>> e['min_value'] = 'MIN VALUE IS %s'
34 >>> e['max_value'] = 'MAX VALUE IS %s'
35 >>> e['max_digits'] = 'MAX DIGITS IS %s'
36->>> e['max_decimal_places'] = 'MAX DP IS %s'
37->>> e['max_whole_digits'] = 'MAX DIGITS BEFORE DP IS %s'
38+>>> e['decimal_places'] = 'MAX DP IS %s'
39+>>> e['total_digits'] = 'MAX DIGITS BEFORE DP IS %s'
40 >>> f = DecimalField(min_value=5, max_value=10, error_messages=e)
41 >>> f2 = DecimalField(max_digits=4, decimal_places=2, error_messages=e)
42 >>> f.clean('')
43Index: docs/newforms.txt
44===================================================================
45--- docs/newforms.txt   (revision 7948)
46+++ docs/newforms.txt   (working copy)
47@@ -1295,8 +1295,7 @@
48     * Validates that the given value is a decimal. Leading and trailing
49       whitespace is ignored.
50     * Error message keys: ``required``, ``invalid``, ``max_value``,
51-      ``min_value``, ``max_digits``, ``max_decimal_places``,
52-      ``max_whole_digits``
53+      ``min_value``, ``max_digits``, ``decimal_places``, ``total_digits``
54 
55 Takes four optional arguments: ``max_value``, ``min_value``, ``max_digits``,
56 and ``decimal_places``. The first two define the limits for the fields value.