Prefix a validation error message while maintaining the existing validation data structure.
(error, prefix, code, params)
| 6 | |
| 7 | |
| 8 | def prefix_validation_error(error, prefix, code, params): |
| 9 | """ |
| 10 | Prefix a validation error message while maintaining the existing |
| 11 | validation data structure. |
| 12 | """ |
| 13 | if error.error_list == [error]: |
| 14 | error_params = error.params or {} |
| 15 | return ValidationError( |
| 16 | # We can't simply concatenate messages since they might require |
| 17 | # their associated parameters to be expressed correctly which |
| 18 | # is not something `format_lazy` does. For example, proxied |
| 19 | # ngettext calls require a count parameter and are converted |
| 20 | # to an empty string if they are missing it. |
| 21 | message=format_lazy( |
| 22 | "{} {}", |
| 23 | SimpleLazyObject(lambda: prefix % params), |
| 24 | SimpleLazyObject(lambda: error.message % error_params), |
| 25 | ), |
| 26 | code=code, |
| 27 | params={**error_params, **params}, |
| 28 | ) |
| 29 | return ValidationError( |
| 30 | [prefix_validation_error(e, prefix, code, params) for e in error.error_list] |
| 31 | ) |
| 32 | |
| 33 | |
| 34 | class CheckPostgresInstalledMixin: |
no test coverage detected