From 237a87f09b3f5ab80c8a4e47e96690c73dfc4336 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Mon, 25 Feb 2019 17:28:30 +0900 Subject: [PATCH] [#1117] Begin grouping validation error messages into seperate tables --- cove_360/lib/threesixtygiving.py | 14 ++++++++++++++ cove_360/templates/cove_360/explore.html | 21 ++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/cove_360/lib/threesixtygiving.py b/cove_360/lib/threesixtygiving.py index 41e5dd08a..a26503515 100644 --- a/cove_360/lib/threesixtygiving.py +++ b/cove_360/lib/threesixtygiving.py @@ -1,4 +1,5 @@ import re +import json from collections import defaultdict, OrderedDict from decimal import Decimal @@ -108,6 +109,19 @@ def common_checks_360(context, upload_dir, json_data, schema_obj): common_checks = common_checks_context(upload_dir, json_data, schema_obj, schema_name, context) cell_source_map = common_checks['cell_source_map'] + validation_errors = context['validation_errors'] + validation_errors_grouped = defaultdict(list) + for error_json, values in validation_errors: + error = json.loads(error_json) + if error['validator'] == 'required': + validation_errors_grouped['required'].append((error_json, values)) + elif error['validator'] in ['format', 'oneOf']: + # NOTE: this assumes oneOf is only used for specifying multiple + # format types, which is true of the 1.0 schema. + validation_errors_grouped['format'].append((error_json, values)) + else: + validation_errors_grouped['other'].append((error_json, values)) + context.update(common_checks['context']) context.update({ 'grants_aggregates': get_grants_aggregates(json_data, ignore_errors=True), diff --git a/cove_360/templates/cove_360/explore.html b/cove_360/templates/cove_360/explore.html index ee295c479..70b00cd7a 100644 --- a/cove_360/templates/cove_360/explore.html +++ b/cove_360/templates/cove_360/explore.html @@ -154,16 +154,27 @@


 {% trans "There are some validation errors in your data, please check them in the table below." %}


+

Missing Fields

+ {% with validation_errors=validation_errors_grouped.required %} {% include "validation_table.html" %} - {% for error_json, values in validation_errors %} - {% with error=error_json|json_decode %} - {% cove_modal_errors className="validation-errors-"|concat:forloop.counter modalTitle=error.message errorList=values file_type=file_type full_table=True %} - {% endwith %} - {% endfor %} + {% endwith %} +

Incorrect Formats

+ {% with validation_errors=validation_errors_grouped.format %} + {% include "validation_table.html" %} + {% endwith %} +

Other

+ {% with validation_errors=validation_errors_grouped.other %} + {% include "validation_table.html" %} + {% endwith %} {% endif %} + {% for error_json, values in validation_errors %} + {% with error=error_json|json_decode %} + {% cove_modal_errors className="validation-errors-"|concat:forloop.counter modalTitle=error.message errorList=values file_type=file_type full_table=True %} + {% endwith %} + {% endfor %} {% endblock validation %} {% block quality_accuracy %}