From 340c12f1f093e281177e2a17337f4d9940a7c083 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson <frjo@xdeb.org> Date: Thu, 4 Oct 2018 14:58:41 +0200 Subject: [PATCH] Easier to read error message for fields that can only be included once. --- opentech/apply/utils/blocks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opentech/apply/utils/blocks.py b/opentech/apply/utils/blocks.py index 124911764..1cd818209 100644 --- a/opentech/apply/utils/blocks.py +++ b/opentech/apply/utils/blocks.py @@ -79,7 +79,7 @@ class CustomFormFieldsBlock(StreamBlock): if duplicates: all_errors.append( - 'You have duplicates of the following non duplicate fields: {}'.format(', '.join(prettify_names(duplicates))) + 'The following fields must be included only once: {}'.format(', '.join(prettify_names(duplicates))) ) for i, block_name in enumerate(block_types): if block_name in duplicates: @@ -117,6 +117,7 @@ class SingleIncludeStatic(StaticBlock): """Helper block which displays additional information about the must include block and helps display the error in a noticeable way. """ + def __init__(self, *args, description='', **kwargs): self.description = description super().__init__(*args, **kwargs) @@ -155,6 +156,7 @@ class MustIncludeFieldBlock(SingleIncludeMixin, FormFieldBlock): """Any block inheriting from this will need to be included in the application forms This data will also be available to query on the submission object """ + def get_field_kwargs(self, struct_value): kwargs = super().get_field_kwargs(struct_value) kwargs['required'] = True -- GitLab