当前位置: 首页>>代码示例>>Python>>正文


Python colander.Length方法代码示例

本文整理汇总了Python中colander.Length方法的典型用法代码示例。如果您正苦于以下问题:Python colander.Length方法的具体用法?Python colander.Length怎么用?Python colander.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在colander的用法示例。


在下文中一共展示了colander.Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: name_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        resource_type = ResourceType.by_name(value)
        if (
            resource_type
            and (
                str(resource_type.id) != request.params.get('id')
                or (
                    str(resource_type.id) == request.params.get('id')
                    and request.view_name == 'copy'
                )
            )
        ):
            raise colander.Invalid(
                node,
                _(u'Resource Type with the same name exists'),
            )
    return colander.All(colander.Length(max=128), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:22,代码来源:resources_types.py

示例2: humanize_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def humanize_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        resource_type = ResourceType.by_humanize(value)
        if (
            resource_type
            and (
                str(resource_type.id) != request.params.get('id')
                or (
                    str(resource_type.id) == request.params.get('id')
                    and request.view_name == 'copy'
                )
            )
        ):
            raise colander.Invalid(
                node,
                _(u'Resource Type with the same humanize exists'),
            )
    return colander.All(colander.Length(max=128), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:22,代码来源:resources_types.py

示例3: start_dt_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def start_dt_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        campaign_id = request.params.get('id')
        if campaign_id:
            return
        if parse_datetime(value) <= datetime.now():
            raise colander.Invalid(
                node,
                _(u'Check datetime'),
            )
    return colander.All(colander.Length(max=255), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:15,代码来源:campaigns.py

示例4: name_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        service = Service.by_name(value)
        if (
            service
            and str(service.id) != request.params.get('id')
        ):
            raise colander.Invalid(
                node,
                _(u'Service with the same name exists'),
            )
    return colander.All(colander.Length(max=255), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:16,代码来源:services.py

示例5: name_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        account_item = AccountItem.by_name(value)
        if (
            account_item
            and str(account_item.id) != request.params.get('id')
        ):
            raise colander.Invalid(
                node,
                _(u'Account Item with the same name exists'),
            )
    return colander.All(colander.Length(max=255), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:16,代码来源:accounts_items.py

示例6: name_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        subaccount = Subaccount.by_name(value)
        if (
            subaccount
            and str(subaccount.id) != request.params.get('id')
        ):
            raise colander.Invalid(
                node,
                _(u'Subaccount with the same name exists'),
            )
    return colander.All(colander.Length(max=255), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:16,代码来源:subaccounts.py

示例7: name_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        supplier_type = SupplierType.by_name(value)
        if (
            supplier_type
            and str(supplier_type.id) != request.params.get('id')
        ):
            raise colander.Invalid(
                node,
                _(u'Supplier type with the same name exists'),
            )
    return colander.All(colander.Length(max=32), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:16,代码来源:suppliers_types.py

示例8: iso_code_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def iso_code_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        country = Country.by_iso_code(value)
        if (
            country
            and str(country.id) != request.params.get('id')
        ):
            raise colander.Invalid(
                node,
                _(u'Country with the same iso code exists'),
            )
    return colander.All(colander.Length(min=2, max=2), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:16,代码来源:countries.py

示例9: name_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        account = Account.by_name(value)
        if (
            account
            and str(account.id) != request.params.get('id')
        ):
            raise colander.Invalid(
                node,
                _(u'Account with the same name exists'),
            )
    return colander.All(colander.Length(max=255), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:16,代码来源:accounts.py

示例10: resource_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def resource_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        path = value.split('.')
        module, attr = '.'.join(path[:-1]), path[-1]
        try:
            mod = importlib.import_module(module)
            if not hasattr(mod, attr):
                raise colander.Invalid(node, _(u"Resource does not exist"))
        except ImportError:
            raise colander.Invalid(node, _(u"Resource module does not exist"))
        except:
            raise colander.Invalid(node, _(u"Check module name"))

        resource_type = ResourceType.by_resource_name(module, attr)
        if (
            resource_type
            and (
                str(resource_type.id) != request.params.get('id')
                or (
                    str(resource_type.id) == request.params.get('id')
                    and request.view_name == 'copy'
                )
            )
        ):
            raise colander.Invalid(
                node,
                _(u'Resource Type with the same resource exists'),
            )

    return colander.All(colander.Length(max=128), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:34,代码来源:resources_types.py

示例11: name_validator

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def name_validator(node, kw):
    request = kw.get('request')

    def validator(node, value):
        mail = Mail.by_name(value)
        if (
            mail
            and str(mail.id) != request.params.get('id')
        ):
            raise colander.Invalid(
                node,
                _(u'Mail with the same name exists'),
            )
    return colander.All(colander.Length(max=255), validator,) 
开发者ID:mazvv,项目名称:travelcrm,代码行数:16,代码来源:mails.py

示例12: __call__

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def __call__(self, node, value):
        """ Returns a ``colander.Function`` validator that uses the context (user)
        to validate the password."""
        user = get_current()
        user_password = getattr(user, 'password', None)
        if value['changepassword'] and \
           user_password and not user.check_password(value['currentuserpassword']):
            raise colander.Invalid(
                node.get('currentuserpassword'),
                _(' Invalid current password'))

        if value['changepassword']:
            colander.Length(min=3, max=100)(node.get('password'),
                                            value['password']) 
开发者ID:ecreall,项目名称:nova-ideo,代码行数:16,代码来源:edit.py

示例13: test_validate_all

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def test_validate_all(self):
        node = colander.SchemaNode(colander.String(),
                                   validator=colander.All(
                                       colander.Length(12, 42),
                                       colander.Regex(r'foo*bar')
                                   ))
        ret = convert(node)
        self.assertDictEqual(ret, {
            'type': 'string',
            'pattern': 'foo*bar',
            'maxLength': 42,
            'minLength': 12,
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:15,代码来源:test_schema.py

示例14: test_validate_length

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def test_validate_length(self):
        node = colander.SchemaNode(colander.String(),
                                   validator=colander.Length(12, 42))
        ret = convert(node)
        self.assertDictEqual(ret, {
            'type': 'string',
            'maxLength': 42,
            'minLength': 12,
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:11,代码来源:test_schema.py

示例15: convert_length_validator_factory

# 需要导入模块: import colander [as 别名]
# 或者: from colander import Length [as 别名]
def convert_length_validator_factory(max_key, min_key):

    def validator_converter(validator):
        converted = None

        if isinstance(validator, colander.Length):
            converted = {}
            if validator.max is not None:
                converted[max_key] = validator.max
            if validator.min is not None:
                converted[min_key] = validator.min

        return converted

    return validator_converter 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:17,代码来源:schema.py


注:本文中的colander.Length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。