utils.validation_error_util — Util for working with ValidationError¶
-
class
ievv_opensource.utils.validation_error_util.ValidationErrorUtil(validation_error)[source]¶ Bases:
objectA wrapper around
django.core.exceptions.ValidationErrorthat 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')orValidationError(['message1', 'message2'])the values will end up in the__all__key of the dict.
-
as_list()[source]¶ Get the ValidationError as a list of
ValidationErrorobjects.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).
-