Skip to content

Commit

Permalink
[#1117] Begin grouping validation error messages into seperate tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb authored and robredpath committed Jun 7, 2019
1 parent 749064f commit 5a3bbfa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
14 changes: 14 additions & 0 deletions cove_360/lib/threesixtygiving.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import json
from collections import defaultdict, OrderedDict
from decimal import Decimal

Expand Down Expand Up @@ -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),
Expand Down
21 changes: 16 additions & 5 deletions cove_360/templates/cove_360/explore.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,27 @@ <h3 class="panel-title panel-title-explore">
<br>
<p class="explanation">&nbsp;{% trans "There are some <strong>validation errors</strong> in your data, please check them in the table below." %}</p>
<br>
<h4>Missing Fields</h4>
{% 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 %}
<h4>Incorrect Formats</h4>
{% with validation_errors=validation_errors_grouped.format %}
{% include "validation_table.html" %}
{% endwith %}
<h4>Other</h4>
{% with validation_errors=validation_errors_grouped.other %}
{% include "validation_table.html" %}
{% endwith %}
{% endif %}
</div>
</div>
</div>
{% 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 %}
Expand Down

0 comments on commit 5a3bbfa

Please sign in to comment.