MCPcopy
hub / github.com/django/django / prefix_validation_error

Function prefix_validation_error

django/contrib/postgres/utils.py:8–31  ·  view source on GitHub ↗

Prefix a validation error message while maintaining the existing validation data structure.

(error, prefix, code, params)

Source from the content-addressed store, hash-verified

6
7
8def 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
34class CheckPostgresInstalledMixin:

Callers 6

to_pythonMethod · 0.90
validateMethod · 0.90
run_validatorsMethod · 0.90
cleanMethod · 0.90
validateMethod · 0.90
run_validatorsMethod · 0.90

Calls 2

ValidationErrorClass · 0.90
SimpleLazyObjectClass · 0.90

Tested by

no test coverage detected