本文整理匯總了Python中django.core.exceptions.ValidationError.schema方法的典型用法代碼示例。如果您正苦於以下問題:Python ValidationError.schema方法的具體用法?Python ValidationError.schema怎麽用?Python ValidationError.schema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.core.exceptions.ValidationError
的用法示例。
在下文中一共展示了ValidationError.schema方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: validate
# 需要導入模塊: from django.core.exceptions import ValidationError [as 別名]
# 或者: from django.core.exceptions.ValidationError import schema [as 別名]
def validate(data, schema):
"""
Validates the data against given schema and checks validity of ds_id and ds_spirit.
:param data: The data to validate
:param schema: The JSON schema to use for validation.
:return: Valid data
"""
if isinstance(data, dict):
properties = data
elif isinstance(data, Individual):
properties = data.properties
else:
raise ValidationError(
"An Individual can only work with a dict as data and got {} instead".format(type(data))
)
if "_id" in properties:
del properties["_id"]
try:
jsonschema.validate(properties, schema)
except SchemaValidationError as exc:
django_exception = ValidationError(exc.message)
django_exception.schema = exc.schema
raise django_exception