當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。