Commit 4f37e535 authored by Pierre Dittgen's avatar Pierre Dittgen

Display body errors only if no structure errors

parent 8034f2fb
...@@ -45,8 +45,6 @@ ...@@ -45,8 +45,6 @@
{% if report.table.errors.structure %} {% if report.table.errors.structure %}
<div> <div>
<h3>Problèmes de structure</h3> <h3>Problèmes de structure</h3>
{{ report.table.errors.structure|length }} erreur(s) détectée(s)
{% for err in report.table.errors.structure %} {% for err in report.table.errors.structure %}
<div class="alert alert-danger"> <div class="alert alert-danger">
{{ err.message | safe}} {{ err.message | safe}}
...@@ -58,9 +56,12 @@ ...@@ -58,9 +56,12 @@
<!-- row checks --> <!-- row checks -->
{% if report.table.errors.body %} {% if report.table.errors.body %}
{% if not report.table.display_body_errors %}
Merci de corriger ce(s) erreur(s) pour visualiser les erreurs de contenu.
{% else %}
<div> <div>
<h3>Problèmes de contenu</h3> <h3>Problèmes de contenu</h3>
{{ report.table.errors.body|length }} erreur(s) détectée(s)
<div class="table-responsive-sm"> <div class="table-responsive-sm">
<table class="table-sm table-bordered table-striped table-hover"> <table class="table-sm table-bordered table-striped table-hover">
<thead class="thead-light"> <thead class="thead-light">
...@@ -100,18 +101,11 @@ ...@@ -100,18 +101,11 @@
</tbody> </tbody>
</table> </table>
</div> </div>
{% endif %}
{% endif %} {% endif %}
</div> </div>
<!--
<pre>
{{ report_str | safe }}
</pre>
-->
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block footer %} {% block footer %}
...@@ -127,4 +121,10 @@ ...@@ -127,4 +121,10 @@
}) })
}) })
</script> </script>
{#
{{ report.table.errors.structure|length }} erreur(s) détectée(s)
{{ report.table.errors.body|length }} erreur(s) détectée(s)
#}
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -156,26 +156,32 @@ def create_validata_report(goodtables_report, schema): ...@@ -156,26 +156,32 @@ def create_validata_report(goodtables_report, schema):
else: else:
report['table']['errors']['body'].append(err) report['table']['errors']['body'].append(err)
# and group body errors by row id # If there are structure errors different to invalid-column-delimiter
rows = [] # => don't display body errors
current_row_id = 0 report['table']['display_body_errors'] = all(err['code'] == 'invalid-column-delimiter'
for err in report['table']['errors']['body']: for err in report['table']['errors']['structure'])
if not 'row-number' in err:
print('ERR', err) if report['table']['display_body_errors']:
row_id = err['row-number'] # and group body errors by row id
del err['row-number'] rows = []
del err['context'] current_row_id = 0
if row_id != current_row_id: for err in report['table']['errors']['body']:
current_row_id = row_id if not 'row-number' in err:
rows.append({'row_id': current_row_id, 'errors': {}}) print('ERR', err)
row_id = err['row-number']
column_id = err.get('column-number') del err['row-number']
if column_id is not None: del err['context']
del err['column-number'] if row_id != current_row_id:
rows[-1]['errors'][column_id] = err current_row_id = row_id
else: rows.append({'row_id': current_row_id, 'errors': {}})
rows[-1]['errors']['row'] = err
report['table']['errors']['by_rows'] = rows column_id = err.get('column-number')
if column_id is not None:
del err['column-number']
rows[-1]['errors'][column_id] = err
else:
rows[-1]['errors']['row'] = err
report['table']['errors']['by_rows'] = rows
return report return report
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment