mirror of
https://github.com/ansible/awx.git
synced 2026-03-26 21:35:01 -02:30
Merge pull request #1546 from AlanCoding/named_words
use named formatting in error messages
This commit is contained in:
@@ -2673,7 +2673,9 @@ class CredentialSerializer(BaseSerializer):
|
|||||||
for field in set(data.keys()) - valid_fields - set(credential_type.defined_fields):
|
for field in set(data.keys()) - valid_fields - set(credential_type.defined_fields):
|
||||||
if data.get(field):
|
if data.get(field):
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{"detail": _("'%s' is not a valid field for %s") % (field, credential_type.name)}
|
{"detail": _("'{field_name}' is not a valid field for {credential_type_name}").format(
|
||||||
|
field_name=field, credential_type_name=credential_type.name
|
||||||
|
)}
|
||||||
)
|
)
|
||||||
value.pop('kind', None)
|
value.pop('kind', None)
|
||||||
return value
|
return value
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ __all__ = ['AutoOneToOneField', 'ImplicitRoleField', 'JSONField',
|
|||||||
def __enum_validate__(validator, enums, instance, schema):
|
def __enum_validate__(validator, enums, instance, schema):
|
||||||
if instance not in enums:
|
if instance not in enums:
|
||||||
yield jsonschema.exceptions.ValidationError(
|
yield jsonschema.exceptions.ValidationError(
|
||||||
_("'%s' is not one of ['%s']") % (instance, "', '".join(enums))
|
_("'{value}' is not one of ['{allowed_values}']").format(
|
||||||
|
value=instance, allowed_values="', '".join(enums))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -729,7 +730,8 @@ class CredentialTypeInputField(JSONSchemaField):
|
|||||||
for key in ('choices', 'multiline', 'format', 'secret',):
|
for key in ('choices', 'multiline', 'format', 'secret',):
|
||||||
if key in field and field['type'] != 'string':
|
if key in field and field['type'] != 'string':
|
||||||
raise django_exceptions.ValidationError(
|
raise django_exceptions.ValidationError(
|
||||||
_('%s not allowed for %s type (%s)' % (key, field['type'], field['id'])),
|
_('{sub_key} not allowed for {element_type} type ({element_id})'.format(
|
||||||
|
sub_key=key, element_type=field['type'], element_id=field['id'])),
|
||||||
code='invalid',
|
code='invalid',
|
||||||
params={'value': value},
|
params={'value': value},
|
||||||
)
|
)
|
||||||
@@ -826,13 +828,15 @@ class CredentialTypeInjectorField(JSONSchemaField):
|
|||||||
).from_string(tmpl).render(valid_namespace)
|
).from_string(tmpl).render(valid_namespace)
|
||||||
except UndefinedError as e:
|
except UndefinedError as e:
|
||||||
raise django_exceptions.ValidationError(
|
raise django_exceptions.ValidationError(
|
||||||
_('%s uses an undefined field (%s)') % (key, e),
|
_('{sub_key} uses an undefined field ({error_msg})').format(
|
||||||
|
sub_key=key, error_msg=e),
|
||||||
code='invalid',
|
code='invalid',
|
||||||
params={'value': value},
|
params={'value': value},
|
||||||
)
|
)
|
||||||
except TemplateSyntaxError as e:
|
except TemplateSyntaxError as e:
|
||||||
raise django_exceptions.ValidationError(
|
raise django_exceptions.ValidationError(
|
||||||
_('Syntax error rendering template for %s inside of %s (%s)') % (key, type_, e),
|
_('Syntax error rendering template for {sub_key} inside of {type} ({error_msg})').format(
|
||||||
|
sub_key=key, type=type_, error_msg=e),
|
||||||
code='invalid',
|
code='invalid',
|
||||||
params={'value': value},
|
params={'value': value},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user