diff --git a/validata_ui_next/templates/validation_report.html b/validata_ui_next/templates/validation_report.html index 44607414a2e28cd3a0e7798abaa506a0481957ba..acd0b7e5f133371d32451076b9dd176f2bd6b352 100644 --- a/validata_ui_next/templates/validation_report.html +++ b/validata_ui_next/templates/validation_report.html @@ -30,17 +30,61 @@ {% else %}

La table est invalide

-

{{ len(report['errors']) }} erreur(s) détectée(s)

+

{{ report['tables'][0]['errors']|length }} erreur(s) détectée(s)

-{% endif %} + + +
+

Erreurs de table

+ +
+ +
+

Erreurs de valeurs

+ + {% for err in report['tables'][0]['errors'] %} + {% if err.context == 'body' %} + + + + + {% for h in report['tables'][0]['headers'] %} + + {% endfor %} + + + + + + + + + +
#{{ h }}
{{ err['row-number'] }} + valeurs à afficher ici avec des couleurs pour souligner les cases en faute !!! +
+ + {% endif %} + {% endfor %} + +
-{{ report_str }}
+
 
+{% endif %} {% endblock %} {% block footer %} {% endblock %} \ No newline at end of file diff --git a/validata_ui_next/views.py b/validata_ui_next/views.py index 8599d53bb001d8bb2fe1b00c9bf1b0f8033d5755..18420dea1f4cbe1609bc494fdc6931756481d755 100644 --- a/validata_ui_next/views.py +++ b/validata_ui_next/views.py @@ -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)} +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): """ Validate source and display report """ report = ValidatorHelper.validate(schema_code, source, source_type) + report = contextualize(report) + preview = compute_source_preview(source) # Complete report