Ticket #2760: validators.diff

File validators.diff, 1.5 KB (added by James Bennett, 18 years ago)

Patch which hopefully fixes this

  • validators.py

     
    352352            float(data)
    353353        except ValueError:
    354354            raise ValidationError, gettext("Please enter a valid decimal number.")
    355         if len(data) > (self.max_digits + 1):
     355        max_allowed_length = data.startswith('-') and (self.max_digits + 2) or (self.max_digits + 1) # Support negative floats which begin with a '-'
     356        if len(data) > max_allowed_length:
    356357            raise ValidationError, ngettext("Please enter a valid decimal number with at most %s total digit.",
    357358                "Please enter a valid decimal number with at most %s total digits.", self.max_digits) % self.max_digits
    358         if (not '.' in data and len(data) > (self.max_digits - self.decimal_places)) or ('.' in data and len(data) > (self.max_digits - (self.decimal_places - len(data.split('.')[1])) + 1)):
     359        if (not '.' in data and len(data) > (max_allowed_length - self.decimal_places)) or ('.' in data and len(data) > (self.max_digits - (self.decimal_places - len(data.split('.')[1])) + 1)):
    359360            raise ValidationError, ngettext( "Please enter a valid decimal number with a whole part of at most %s digit.",
    360361                "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)
    361362        if '.' in data and len(data.split('.')[1]) > self.decimal_places:
Back to Top