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