本文整理汇总了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)
示例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')
示例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'
)
示例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'
)
示例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')
示例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')
示例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')
示例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
示例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."]}),
)
示例10: validate_choice
# 需要导入模块: from schematics import exceptions [as 别名]
# 或者: from schematics.exceptions import ValidationError [as 别名]
def validate_choice(self, value):
self._to_name(value, ValidationError)
示例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)
示例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)))
示例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")
示例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)))
示例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'])))