-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCDS - Group validation errors by type
- Loading branch information
Showing
4 changed files
with
176 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from collections import defaultdict | ||
import json | ||
|
||
|
||
def group_validation_errors(validation_errors): | ||
validation_errors_grouped = defaultdict(list) | ||
for error_json, values in validation_errors: | ||
error = json.loads(error_json) | ||
if error['message_type'] == 'required': | ||
validation_errors_grouped['required'].append((error_json, values)) | ||
elif error['message_type'] in ['format', 'pattern', 'number', 'minLength', 'string', 'date-time', 'uri']: | ||
validation_errors_grouped['format'].append((error_json, values)) | ||
else: | ||
validation_errors_grouped['other'].append((error_json, values)) | ||
return validation_errors_grouped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{% load i18n %} | ||
{% load cove_tags %} | ||
|
||
<table class="table table-condensed"> | ||
<thead> | ||
<tr> | ||
<th>{% trans 'Error Description' %}</th> | ||
<th>{% trans 'Error Count' %}</th> | ||
<th>{% trans 'First 3 Examples' %}</th> | ||
<th>{% trans 'Location of first 3 errors' %}</th> | ||
{% if file_type == 'xlsx' or file_type == 'csv' %} | ||
<th>{% trans 'Spreadsheet Location of first 3 errors' %}</th> | ||
{% endif %} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for error_json, values in validation_errors %} | ||
{% with error=error_json|json_decode %} | ||
<tr> | ||
{% if error.message_safe %} | ||
<td> | ||
<p> | ||
<strong>{{ error.message_safe | safe }}</strong> | ||
{% if error.message_type in common_error_types %} | ||
<a href="{% url 'common_errors' %}#{{error.message_type}}" target="_blank">(more info)</a> | ||
{% endif %} | ||
</p> | ||
{% if 'schema_title' in error %} | ||
<div class="well well-sm"> | ||
<h4>{{ error.schema_title }}</h4> | ||
<p>{{ error.schema_description_safe | safe }}</p> | ||
</div> | ||
{% endif %} | ||
</td> | ||
{% elif error.message_type in common_error_types %} | ||
<td><a href="{% url 'common_errors' %}#{{error.message_type}}"> {{error.message}} </a></td> | ||
{% else %} | ||
<td>{{error.message}}</td> | ||
{% endif %} | ||
<td class="text-center"> | ||
{% if values|length > 3 %} | ||
{% if error_prefix %} | ||
<a data-toggle="modal" data-target=".{{"validation-errors-"|concat:error_prefix|concat:forloop.counter}}"> | ||
{% else %} | ||
<a data-toggle="modal" data-target=".{{"validation-errors-"|concat:forloop.counter}}"> | ||
{% endif %} | ||
{{values|length}} | ||
</a> | ||
{% else %} | ||
{{values|length}} | ||
{% endif %} | ||
</td> | ||
<td> | ||
<ul class="list-unstyled"> | ||
{% for value in values|slice:":3" %} | ||
<li> {{value.value}} </li> | ||
{% endfor %} | ||
</ul> | ||
</td> | ||
<td> | ||
<ul class="list-unstyled"> | ||
{% for value in values|slice:":3" %} | ||
<li> | ||
{% if value.line %} | ||
<b>{% trans 'Path:' %}</b> {{value.path}} | ||
<b>{% trans 'Line:' %}</b> {{value.line}} | ||
{% else %} | ||
{{ value.path }} | ||
{% endif %} | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</td> | ||
{% if file_type == 'xlsx' or file_type == 'csv' %} | ||
<td style="white-space: nowrap"> | ||
<ul class="list-unstyled"> | ||
{% for value in values|slice:":3" %} | ||
<li> <b>Sheet:</b> {{value.sheet}} <b>Row:</b> {{value.row_number}} {% if value.header %} <b>Column:</b> {{value.header}} {% endif %} </li> | ||
{% endfor %} | ||
</ul> | ||
</td> | ||
{% endif %} | ||
</tr> | ||
{% endwith %} | ||
{% endfor %} | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters