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


Python exceptions.ValidationError方法代码示例

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


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

示例1: _update_membership

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def _update_membership(self, membership_change):
        stripe.api_key = os.environ['STRIPE_PRIVATE_KEY']
        active_membership = self._get_active_membership()
        if membership_change['membership_type'] is None:
            self._cancel_membership(active_membership)
        elif membership_change['new_membership']:
            if active_membership is None:
                self._add_membership(membership_change, active_membership)
            else:
                raise ValidationError(
                    'new membership requested for account with active '
                    'membership'
                )
        else:
            if active_membership is None:
                raise ValidationError(
                    'membership change requested for account with no '
                    'active membership'
                )
            else:
                self._cancel_membership(active_membership)
                self._add_membership(membership_change, active_membership) 
开发者ID:MycroftAI,项目名称:selene-backend,代码行数:24,代码来源:account.py

示例2: agreement_accepted

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def agreement_accepted(value):
    if not value:
        raise ValidationError('agreement not accepted') 
开发者ID:MycroftAI,项目名称:selene-backend,代码行数:5,代码来源:account.py

示例3: validate_email

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_email(self, data, value):
        if data['federated_token'] is None:
            if value is None:
                raise ValidationError(
                    'either a federated login or an email address is required'
                ) 
开发者ID:MycroftAI,项目名称:selene-backend,代码行数:8,代码来源:account.py

示例4: validate_password

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_password(self, data, value):
        if data['email'] is not None:
            if value is None:
                raise ValidationError(
                    'email address must be accompanied by a password'
                ) 
开发者ID:MycroftAI,项目名称:selene-backend,代码行数:8,代码来源:account.py

示例5: validate_membership_type

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_membership_type(self, data, value):
        if data['new_membership'] and value is None:
            raise ValidationError('new memberships require a membership type') 
开发者ID:MycroftAI,项目名称:selene-backend,代码行数:5,代码来源:account.py

示例6: validate_payment_method

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_payment_method(self, data, value):
        if data['new_membership'] and value is None:
            raise ValidationError('new memberships require a payment method') 
开发者ID:MycroftAI,项目名称:selene-backend,代码行数:5,代码来源:account.py

示例7: validate_pairing_code

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_pairing_code(pairing_code):
    cache_key = 'pairing.code:' + pairing_code
    cache = SeleneCache()
    pairing_cache = cache.get(cache_key)

    if pairing_cache is None:
        raise ValidationError('pairing code not found') 
开发者ID:MycroftAI,项目名称:selene-backend,代码行数:9,代码来源:device.py

示例8: validate_skill_gid

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_skill_gid(self, data, value):
        if data['skill_gid'] is None and data['identifier'] is None:
            raise ValidationError(
                'skill should have either skill_gid or identifier defined'
            )
        return value 
开发者ID:MycroftAI,项目名称:selene-backend,代码行数:8,代码来源:device_skill_settings.py

示例9: test_validation_error_on_model_level_validation

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def test_validation_error_on_model_level_validation():
    class TestModel(Model):
        field_a = StringType()

        def validate_field_a(self, data, value):
            raise ValidationError("Model-level validation failed.")

    _test_data(
        model=TestModel,
        data={"field_a": "some_data"},
        expected=(False, {"field_a": ["Model-level validation failed."]}),
    ) 
开发者ID:scrapinghub,项目名称:spidermon,代码行数:14,代码来源:test_validators_schematics.py

示例10: validate_choice

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_choice(self, value):
        self._to_name(value, ValidationError) 
开发者ID:jmcarp,项目名称:betfair.py,代码行数:4,代码来源:types.py

示例11: test_encode_model_invalid

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def test_encode_model_invalid():
    raw = {'model': models.MarketDescription()}
    with pytest.raises(ValidationError):
        json.dumps(raw, cls=BetfairEncoder) 
开发者ID:jmcarp,项目名称:betfair.py,代码行数:6,代码来源:test_utils.py

示例12: validate_dkpp

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_dkpp(items, *args):
    if items and not any([i.scheme in ADDITIONAL_CLASSIFICATIONS_SCHEMES for i in items]):
        raise ValidationError(u"One of additional classifications should be one of [{0}].".format(', '.join(ADDITIONAL_CLASSIFICATIONS_SCHEMES))) 
开发者ID:openprocurement,项目名称:openprocurement.api,代码行数:5,代码来源:utils.py

示例13: validate_startDate

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_startDate(self, data, value):
        if value and data.get('endDate') and data.get('endDate') < value:
            raise ValidationError(u"period should begin before its end") 
开发者ID:openprocurement,项目名称:openprocurement.api,代码行数:5,代码来源:models.py

示例14: validate_id

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_id(self, data, code):
        if data.get('scheme') == u'CPV' and code not in CPV_CODES:
            raise ValidationError(BaseType.MESSAGES['choices'].format(unicode(CPV_CODES)))
        elif data.get('scheme') == u'ДК021' and code not in DK_CODES:
            raise ValidationError(BaseType.MESSAGES['choices'].format(unicode(DK_CODES))) 
开发者ID:openprocurement,项目名称:openprocurement.api,代码行数:7,代码来源:models.py

示例15: validate_scheme

# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_scheme(self, data, scheme):
        schematics_document = get_schematics_document(data['__parent__'])
        if (schematics_document.get('revisions')[0].date if schematics_document.get('revisions') else get_now()) > CPV_BLOCK_FROM and scheme != u'ДК021':
            raise ValidationError(BaseType.MESSAGES['choices'].format(unicode([u'ДК021']))) 
开发者ID:openprocurement,项目名称:openprocurement.api,代码行数:6,代码来源:models.py


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