From c8837fb119a1b618cdfadb7842dae83037db0d92 Mon Sep 17 00:00:00 2001 From: Pierre Dittgen Date: Thu, 27 Sep 2018 17:07:28 +0200 Subject: [PATCH] Error contextualizing --- .../templates/validation_report.html | 50 +++++++++++++++++-- validata_ui_next/views.py | 49 ++++++++++++++++++ 2 files changed, 96 insertions(+), 3 deletions(-) diff --git a/validata_ui_next/templates/validation_report.html b/validata_ui_next/templates/validation_report.html index 4460741..acd0b7e 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 8599d53..18420de 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 -- GitLab