Exceptions¶
-
exception
valedictory.exceptions.
BaseValidationException
[source]¶ All validation exceptions will be subclasses of this exception.
-
exception
valedictory.exceptions.
InvalidDataException
(errors={})[source]¶ Lists of validation errors for each field in a validator.
Only filled out for a field if the field has an error.
-
invalid_fields
¶ A dict with the validation exceptions for all fields that failed validation. Normal field errors will be a
ValidationException
instance, while errors forListField
andNestedValidator
may also beInvalidDataException
instances.
-
flatten
()[source]¶ Yield a pair of
(path, errors)
for each error.>>> list(errors.flatten()) [ (['bar'], ['Unknown field']), (['foo'], ['This field can not be empty']), ]
If an error is a
InvalidDataException
, then errors are recursively extracted.path
will be an array of the path to the error.errors
will be an array of the error messages from these errors.If validator was constructed for a shopping cart, which had user details and a list of items in a shopping cart, made using a
NestedValidator
inside aListField
, some possible flattened errors might be:>>> list(errors.flatten()) [ (['name'], ['This field can not be empty']), (['items', 2, 'quantity'], ['This must be equal to or greater than the minimum of 1']), ]
-
-
exception
valedictory.exceptions.
ValidationException
(message, code, **kwargs)[source]¶ A field has failed validation.
-
msg
¶ The validation error as a human readable string. This error is translatable via gettext, and should not be used for checking the type of error
-
code
¶ The validation error code as a string. This can be used to check the type of error
-