Code

Ticket #1088: isValidFloat.diff

File isValidFloat.diff, 1.3 KB (added by Yango, 8 years ago)

A diff for the validator, don't pay attention to the pasted code as it's buggy

Line 
1Index: core/validators.py
2===================================================================
3--- core/validators.py  (revision 1718)
4+++ core/validators.py  (working copy)
5@@ -350,6 +350,10 @@
6         if len(data) > (self.max_digits + 1):
7             raise ValidationError, ngettext( "Please enter a valid decimal number with at most %s total digit.",
8                 "Please enter a valid decimal number with at most %s total digits.", self.max_digits) % self.max_digits
9+        if (not '.' in data and len(data) > (self.max_digits - self.decimal_places)) \
10+            or ('.' in data and len(data) > (self.max_digits - (self.decimal_places - len(data.split('.')[1])) + 1)):
11+            raise ValidationError, ngettext( "Please enter a valid decimal number with a whole part of at most %s digit.",
12+                "Please enter a valid decimal number with a whole part of at most %s digits.", str(self.max_digits-self.decimal_places)) % str(self.max_digits-self.decimal_places)
13         if '.' in data and len(data.split('.')[1]) > self.decimal_places:
14             raise ValidationError, ngettext("Please enter a valid decimal number with at most %s decimal place.",
15                 "Please enter a valid decimal number with at most %s decimal places.", self.decimal_places) % self.decimal_places