From 7290cbef7fe4d9929e2a62ac62841aebd75191fa Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Tue, 30 Jan 2018 15:03:45 +0000 Subject: [PATCH] make sure the error message returns human friendly text --- opentech/apply/funds/blocks.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/opentech/apply/funds/blocks.py b/opentech/apply/funds/blocks.py index 0cbf96ae8..65caa5c94 100644 --- a/opentech/apply/funds/blocks.py +++ b/opentech/apply/funds/blocks.py @@ -22,6 +22,14 @@ def find_duplicates(items): return duplicates +def prettify_names(sequence): + return [nice_field_name(item) for item in sequence] + + +def nice_field_name(name): + return name.title().replace('_', ' ') + + class RichTextFieldBlock(TextFieldBlock): widget = TinyMCE(mce_attrs={ 'elementpath': False, @@ -60,12 +68,12 @@ class CustomFormFieldsBlock(FormFieldsBlock): all_errors = list() if missing: all_errors.append( - 'You are missing the following required fields: {}'.format(', '.join(missing).title()) + 'You are missing the following required fields: {}'.format(', '.join(prettify_names(missing))) ) if duplicates: all_errors.append( - 'You have duplicates of the following required fields: {}'.format(', '.join(duplicates).title()) + 'You have duplicates of the following required fields: {}'.format(', '.join(prettify_names(duplicates))) ) for i, block_name in enumerate(block_types): if block_name in duplicates: -- GitLab