Commit 4b389be2 authored by Pierre Dittgen's avatar Pierre Dittgen

Externalize table preview

parent 6fd32a87
<p class="text">
Affichage de {{ preview.rows_nb }} lignes sur {{ preview.total_rows_nb }} au total
</p>
<div class="table-responsive">
<table class="table table-striped table-bordered table-sm table-hover">
<thead class="thead-light">
<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>
</div>
\ No newline at end of file
......@@ -21,33 +21,17 @@
</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>
{% include 'table_preview.html' %}
{% else %}
<h2>La table est invalide</h2>
<p>{{ report['error-count'] }} erreur(s) détectée(s)</p>
<p>{{ len(report['errors']) }} erreur(s) détectée(s)</p>
{% endif %}
......
......@@ -19,15 +19,16 @@ def compute_source_preview(source, max_rows=5):
""" Computes table preview """
header = None
rows = []
nb_rows = 0
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}
nb_rows += 1
if len(rows) <= max_rows:
rows.append(row)
return {'header': header, 'data_rows': rows, 'total_rows_nb': nb_rows, 'rows_nb': len(rows)}
def validate(schema_code, source, source_type):
......@@ -36,10 +37,14 @@ def validate(schema_code, source, source_type):
report = ValidatorHelper.validate(schema_code, source, source_type)
preview = compute_source_preview(source)
# Complete report
val_info = ValidatorHelper.schema_info(schema_code)
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))
report_str=json.dumps(report, sort_keys=True, indent=2),
breadcrumbs=[{'url': url_for('home'), 'title': 'Accueil'},
{'url': url_for('scdl_validator', val_code=schema_code), 'title': val_info['title']}])
# 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