Returns a dictionary of all errors within a document Keys are field names or list indices and values are the validation error messages, or a nested dictionary of errors for an embedded document or list.
(self)
| 117 | message = property(_get_message, _set_message) |
| 118 | |
| 119 | def to_dict(self): |
| 120 | """Returns a dictionary of all errors within a document |
| 121 | |
| 122 | Keys are field names or list indices and values are the |
| 123 | validation error messages, or a nested dictionary of |
| 124 | errors for an embedded document or list. |
| 125 | """ |
| 126 | |
| 127 | def build_dict(source): |
| 128 | errors_dict = {} |
| 129 | if isinstance(source, dict): |
| 130 | for field_name, error in source.items(): |
| 131 | errors_dict[field_name] = build_dict(error) |
| 132 | elif isinstance(source, ValidationError) and source.errors: |
| 133 | return build_dict(source.errors) |
| 134 | else: |
| 135 | return str(source) |
| 136 | |
| 137 | return errors_dict |
| 138 | |
| 139 | if not self.errors: |
| 140 | return {} |
| 141 | |
| 142 | return build_dict(self.errors) |
| 143 | |
| 144 | def _format_errors(self): |
| 145 | """Returns a string listing all errors within a document""" |
no outgoing calls