utils.validation_error_util — Util for working with ValidationError

class ievv_opensource.utils.validation_error_util.ValidationErrorUtil(validation_error)[source]

Bases: object

A wrapper around django.core.exceptions.ValidationError that provides useful extra functionality.

Examples

Get a serializable dict:

ValidationErrorUtil(some_validation_error).as_serializable_dict()

Convert ValidationError to rest_framework.exceptions.ValidationError:

ValidationErrorUtil(some_validation_error).as_drf_validation_error()
as_dict()[source]

Get the ValidationError as a dict mapping fieldname to a list of ValidationError object.

Works no matter how the ValidationError was created. If the ValidationError was created with ValidationError('message') or ValidationError(['message1', 'message2']) the values will end up in the __all__ key of the dict.

as_list()[source]

Get the ValidationError as a list of ValidationError objects.

Works even if the ValidationError was created with a dict as input.

as_serializable_list()[source]

Get the ValidationError as a serializable list (a flat list with all the error messages).

as_serializable_dict()[source]

Get the ValidationError as a serializable dict - a dict mapping fieldname to a list of error messages. If the ValidationError was not created with a dict as input, the error messages will be added to the __all__ key.

as_drf_validation_error()[source]

Convert the ValidationError to a rest_framework.exceptions.ValidationError.