diff --git a/setup.py b/setup.py index 2ce6f9c98c67a73d973f67bed7833ce598819e19..8f7b31e20b9943daa4256c214559123bc0d34992 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,8 @@ setup( 'flask', 'requests', 'ujson', - 'validata_validate' + 'validata_validate', + 'goodtables', + 'tabulator' ] ) diff --git a/validata_ui_next/templates/validation_report.html b/validata_ui_next/templates/validation_report.html new file mode 100644 index 0000000000000000000000000000000000000000..62de88310babdf03766789d9595f72144be92b3e --- /dev/null +++ b/validata_ui_next/templates/validation_report.html @@ -0,0 +1,62 @@ +{% extends "base.html" %} +{% block title %}{{ title }}{% endblock %} +{% block head %} +{{ super() }} +{% endblock %} +{% block content %} +
+ {% if source_type == 'file' %}Fichier{% endif %} + {% if source_type == 'url' %}URL{% endif %} + à valider : {{ source }} +
+{{ col }} | + {% endfor %} +
---|
{{ val }} | + {% endfor %} +
Aucune erreur détectée
+{% else %} +{{ report['error-count'] }} erreur(s) détectée(s)
+{% endif %} + + + + ++{{ report_str }} ++ +{% endblock %} +{% block footer %} +{% endblock %} \ No newline at end of file diff --git a/validata_ui_next/validate.py b/validata_ui_next/validate.py index d8bc0cbcfd02b51d45abb318d4f7006970fe7ad1..64057eac1944a93276e1da68cf0edc4e9f9587b8 100644 --- a/validata_ui_next/validate.py +++ b/validata_ui_next/validate.py @@ -75,7 +75,6 @@ class ValidatorHelper: # All keys but schema* and custom_checks* d2 = {k: v for k, v in cls.schema_dict[schema_code].items() if not k.startswith('schema') and not k.startswith('custom_checks')} - print('D2 =', d2) return {**d1, 'code': schema_code, **d2} diff --git a/validata_ui_next/views.py b/validata_ui_next/views.py index 5c7ca00faf4433cb6a14f9410f7eed3a1e547429..2af110c0315347c61914073da731bd275a951cc2 100644 --- a/validata_ui_next/views.py +++ b/validata_ui_next/views.py @@ -12,12 +12,35 @@ from validata_ui_next.util import flash_error, flash_info, flash_success, flash_ from validata_ui_next.validate import ValidatorHelper from flask import Flask, jsonify, redirect, render_template, request, url_for - - -def validate(schema_code, source, res_type): - report = ValidatorHelper.validate(schema_code, source, res_type) - - return jsonify(report) +import tabulator + + +def compute_source_preview(source, max_rows=5): + """ Computes table preview """ + header = None + nb_rows = 0 + rows = [] + with tabulator.Stream(source) as stream: + for row in stream: + if header is None: + header = row + else: + rows.append(row) + if len(rows) == max_rows: + break + return {'header': header, 'data_rows': rows} + + +def validate(schema_code, source, source_type): + """ Validate source and display report """ + + report = ValidatorHelper.validate(schema_code, source, source_type) + preview = compute_source_preview(source) + + return render_template('validation_report.html', title='Rapport de validation', + val_info=ValidatorHelper.schema_info(schema_code), report=report, + source=source, source_type=source_type, preview=preview, + report_str=json.dumps(report, sort_keys=True, indent=2)) # Routes