From d8e8d1d59754f60be4a1fab87041b56dedfe059d Mon Sep 17 00:00:00 2001 From: mdipierro Date: Fri, 11 Oct 2013 16:59:05 -0500 Subject: [PATCH] fixed problem with IS_INT_IN_RANGE for large numbers --- VERSION | 2 +- gluon/dal.py | 2 +- gluon/validators.py | 21 +++++---------------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/VERSION b/VERSION index c843f9ce..4e90ec7e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.7.2-stable+timestamp.2013.10.09.11.56.54 +Version 2.7.2-stable+timestamp.2013.10.11.16.58.14 diff --git a/gluon/dal.py b/gluon/dal.py index f829f0f4..1a63ed47 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -6926,7 +6926,7 @@ def sqlhtml_validators(field): elif field_type == 'double' or field_type == 'float': requires.append(validators.IS_FLOAT_IN_RANGE(-1e100, 1e100)) elif field_type in ('integer','bigint'): - requires.append(validators.IS_INT_IN_RANGE(-1e100, 1e100)) + requires.append(validators.IS_INT_IN_RANGE(-2**31, 2**31-1)) elif field_type.startswith('decimal'): requires.append(validators.IS_DECIMAL_IN_RANGE(-10**10, 10**10)) elif field_type == 'date': diff --git a/gluon/validators.py b/gluon/validators.py index 9dde1ad2..e0ad0fdd 100644 --- a/gluon/validators.py +++ b/gluon/validators.py @@ -692,7 +692,7 @@ class IS_INT_IN_RANGE(Validator): >>> IS_INT_IN_RANGE(1,5)(5) (5, 'enter an integer between 1 and 4') >>> IS_INT_IN_RANGE(1,5)(3.5) - (3, 'enter an integer between 1 and 4') + (3.5, 'enter an integer between 1 and 4') >>> IS_INT_IN_RANGE(None,5)('4') (4, None) >>> IS_INT_IN_RANGE(None,5)('6') @@ -741,24 +741,13 @@ class IS_INT_IN_RANGE(Validator): % dict(min=self.minimum, max=self.maximum - 1) def __call__(self, value): - try: - fvalue = float(value) + if value and str(value).isdigit(): value = int(value) - if value != fvalue: - return (value, self.error_message) - if self.minimum is None: - if self.maximum is None or value < self.maximum: - return (value, None) - elif self.maximum is None: - if value >= self.minimum: - return (value, None) - elif self.minimum <= value < self.maximum: - return (value, None) - except ValueError: - pass + if ((self.minimum is None or value >= self.minimum) and + (self.maximum is None or value < self.maximum)): + return (value, None) return (value, self.error_message) - def str2dec(number): s = str(number) if not '.' in s: