Commit c8837fb1 authored by Pierre Dittgen's avatar Pierre Dittgen

Error contextualizing

parent 4b389be2
...@@ -30,17 +30,61 @@ ...@@ -30,17 +30,61 @@
{% else %} {% else %}
<h2>La table est invalide</h2> <h2>La table est invalide</h2>
<p>{{ len(report['errors']) }} erreur(s) détectée(s)</p> <p>{{ report['tables'][0]['errors']|length }} erreur(s) détectée(s)</p>
{% endif %} <!-- table checks -->
<div>
<h4>Erreurs de table</h4>
<ul>
{% for err in report['tables'][0]['errors'] %}
{% if err.context == 'table' or err.context == 'head' %}
<li>
<pre>{{ err }}</pre>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
<!-- row checks -->
<div>
<h4>Erreurs de valeurs</h4>
{% for err in report['tables'][0]['errors'] %}
{% if err.context == 'body' %}
<table>
<thead>
<th>#</th>
{% for h in report['tables'][0]['headers'] %}
<th>{{ h }}</th>
{% endfor %}
</thead>
<!-- TODO: regrouper les erreurs par ligne ? -->
<!-- Récupérer les valeurs de la ligne à partir de tabulator -->
<tbody>
<tr>
<td>{{ err['row-number'] }}</td>
<td colspan="{{report['tables'][0]['headers']|length}}">
valeurs à afficher ici avec des couleurs pour souligner les cases en faute !!!
</td>
</tr>
</tbody>
</table>
{% endif %}
{% endfor %}
</div>
<pre> <pre>
{{ report_str }} <!-- {{ report_str }} -->
</pre> </pre>
{% endif %}
{% endblock %} {% endblock %}
{% block footer %} {% block footer %}
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -31,10 +31,59 @@ def compute_source_preview(source, max_rows=5): ...@@ -31,10 +31,59 @@ def compute_source_preview(source, max_rows=5):
return {'header': header, 'data_rows': rows, 'total_rows_nb': nb_rows, 'rows_nb': len(rows)} return {'header': header, 'data_rows': rows, 'total_rows_nb': nb_rows, 'rows_nb': len(rows)}
ERR_CODE_TO_CONTEXT = dict([
# TODO: gets it from spec.json
('duplicate-header', 'head'),
('extra-value', 'body'),
('missing-value', 'body'),
('source-error', 'table'),
('schema-error', 'table'),
('non-matching-header', 'head'),
('blank-row', 'body'),
('blank-header', 'head'),
('enumerable-constraint', 'body'),
('http-error', 'table'),
('scheme-error', 'table'),
('type-or-format-error', 'body'),
('format-error', 'table'),
('extra-header', 'head'),
('pattern-constraint', 'body'),
('required-constraint', 'body'),
('missing-header', 'head'),
('maximum-length-constraint', 'body'),
('maximum-constraint', 'body'),
('minimum-length-constraint', 'body'),
('encoding-error', 'table'),
('io-error', 'table'),
('unique-constraint', 'body'),
('duplicate-row', 'body'),
('minimum-constraint', 'body'),
# TODO: get it from validata_validate
('wrong-column-delimiter', 'table')
# Custom checks fall in default case: body
])
def contextualize(report):
""" add context to errors """
errors = report['tables'][0].get('errors')
if errors is None:
return report
errors = [{**err, 'context': ERR_CODE_TO_CONTEXT.get(err['code'], 'body')} for err in errors]
report['tables'][0]['errors'] = errors
return report
def validate(schema_code, source, source_type): def validate(schema_code, source, source_type):
""" Validate source and display report """ """ Validate source and display report """
report = ValidatorHelper.validate(schema_code, source, source_type) report = ValidatorHelper.validate(schema_code, source, source_type)
report = contextualize(report)
preview = compute_source_preview(source) preview = compute_source_preview(source)
# Complete report # Complete 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