示例#1
0
文件: chain.py 项目: dtgit/dtedu
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
示例#2
0
    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
示例#3
0
文件: chain.py 项目: CGTIC/Plone_SP
    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