def test(): """Little test script """ isEmptyURL = ValidationChain('isEmptyURL', validators = (('isEmpty', V_SUFFICIENT), ('isURL', V_REQUIRED)), register=True ) # v = validationService.validatorFor('isEmptyURL') assert(v is isEmptyURL) assert(v('http://www.example.org') is True) assert(v('') is True) assert(type(v('www.example.org')) is StringType) # error isIntOrEmpty = ValidationChain('isIntOrEmpty') isIntOrEmpty.appendSufficient('isEmpty') from validators.RegexValidator import RegexValidator isPosInt = RegexValidator('isInt', r'^([+])?\d+$', title='', description='') isIntOrEmpty.appendRequired(isPosInt) validationService.register(isIntOrEmpty) v = validationService.validatorFor('isIntOrEmpty') assert(v is isIntOrEmpty) assert(v('') is True) assert(v('1') is True) assert(type(v('-1')) is StringType) # error assert(type(v('a')) is StringType) # error
def setValidator(self, id_or_obj, position=None): """Set validator """ validator = validationService.validatorFor(id_or_obj) if position is None: self._chain.append(validator) else: self._chain.insert(position, validator) return validator