@@ -280,6 +280,10 @@ class TestValidators(unittest.TestCase):
|
||||
self.assertEqual(rtn, ([1, 2], 'Enter between 10 and 100 values'))
|
||||
rtn = IS_LIST_OF(IS_INT_IN_RANGE(0, 10), maximum=2)([1,2,3])
|
||||
self.assertEqual(rtn, ([1, 2, 3], 'Enter between 0 and 2 values'))
|
||||
# regression test for issue 742
|
||||
rtn = IS_LIST_OF(minimum=1)('')
|
||||
self.assertEqual(rtn, ([], 'Enter between 1 and 100 values'))
|
||||
|
||||
|
||||
def test_IS_EMPTY_OR(self):
|
||||
rtn = IS_EMPTY_OR(IS_EMAIL())('abc@def.com')
|
||||
|
||||
@@ -2507,9 +2507,10 @@ class IS_LIST_OF(Validator):
|
||||
ivalue = value
|
||||
if not isinstance(value, list):
|
||||
ivalue = [ivalue]
|
||||
if not self.minimum is None and len(ivalue) < self.minimum:
|
||||
ivalue = [i for i in ivalue if str(i).strip()]
|
||||
if self.minimum is not None and len(ivalue) < self.minimum:
|
||||
return (ivalue, translate(self.error_message) % dict(min=self.minimum, max=self.maximum))
|
||||
if not self.maximum is None and len(ivalue) > self.maximum:
|
||||
if self.maximum is not None and len(ivalue) > self.maximum:
|
||||
return (ivalue, translate(self.error_message) % dict(min=self.minimum, max=self.maximum))
|
||||
new_value = []
|
||||
other = self.other
|
||||
@@ -2517,13 +2518,12 @@ class IS_LIST_OF(Validator):
|
||||
if not isinstance(other, (list,tuple)):
|
||||
other = [other]
|
||||
for item in ivalue:
|
||||
if str(item).strip():
|
||||
v = item
|
||||
for validator in other:
|
||||
(v, e) = validator(v)
|
||||
if e:
|
||||
return (ivalue, e)
|
||||
new_value.append(v)
|
||||
v = item
|
||||
for validator in other:
|
||||
(v, e) = validator(v)
|
||||
if e:
|
||||
return (ivalue, e)
|
||||
new_value.append(v)
|
||||
ivalue = new_value
|
||||
return (ivalue, None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user