Commit ed69148a authored by Pierre Dittgen's avatar Pierre Dittgen

First display of table preview

parent 62c085e8
......@@ -27,6 +27,8 @@ setup(
'flask',
'requests',
'ujson',
'validata_validate'
'validata_validate',
'goodtables',
'tabulator'
]
)
{% extends "base.html" %}
{% block title %}{{ title }}{% endblock %}
{% block head %}
{{ super() }}
{% endblock %}
{% block content %}
<h1>{{ title }}</h1>
<div class="card bg-faded" style="width: 30rem;">
<div class="card-body">
<h5 class="card-title">
Schéma {{ val_info.code }}
<span class="badge badge-primary">{{ val_info.version }}</span>
</h5>
<h6 class="card-subtitle mb-2 text-muted">{{ val_info.description }}</h6>
<p class="text">
{% if source_type == 'file' %}Fichier{% endif %}
{% if source_type == 'url' %}URL{% endif %}
à valider : {{ source }}
</p>
</div>
</div>
<h2>Aperçu</h2>
<table class="table table-striped table-bordered">
<thead>
<tr>
{% for col in preview.header %}
<th scope="col">{{ col }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in preview.data_rows %}
<tr>
{% for val in row %}
<td>{{ val }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% if report.valid %}
<h2>La table est valide</h2>
<p>Aucune erreur détectée</p>
{% else %}
<h2>La table est invalide</h2>
<p>{{ report['error-count'] }} erreur(s) détectée(s)</p>
{% endif %}
<pre>
{{ report_str }}
</pre>
{% endblock %}
{% block footer %}
{% endblock %}
\ No newline at end of file
......@@ -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}
......
......@@ -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
......
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