Commit b3c3e09d authored by Pierre Dittgen's avatar Pierre Dittgen

Columns table

parent fdd44444
......@@ -22,9 +22,6 @@
{% endif %}
<h1>{{ title }}</h1>
<p class="text">Validation effectuée {{ validation_date }}</p>
<p class="text alert alert-info hidden-print">
Pour relancer la validation, <a href="#" onclick="location.reload();">rechargez</a> la page.
</p>
{% if print_mode %}
</div>
<div class="col-md-7">
......@@ -99,18 +96,48 @@
{{ macros.error_statistics(report) }}
<div>
<h3>Problèmes de structure</h3>
{% if report.table.errors.structure %}
{% for err in report.table.errors.structure %}
<div class="alert alert-danger">
{{ err.message }}
</div>
{% endfor %}
{% else %}
<p class="text">Aucune erreur de structure</p>
<h3>Problèmes de structure</h3>
{% if report.table.errors.structure %}
{# Non-column errors #}
{% for err in report.table.errors.structure %}
{% if not err.in_column_comp %}
{{ err.content | safe }}
{% endif %}
{% endfor %}
{# Column errors #}
{% for err in report.table.errors.structure %}
{% if err.in_column_comp %}
{{ err.content | safe }}
{% endif %}
{% endfor %}
{# Afficher un tableau de comparaison des colonnes #}
{% if report.table.column_comparison_needed %}
<table class="table table-bordered table-sm table-striped">
<thead class="thead-light">
<tr>
<th scope="col">Colonnes du fichier</th>
<th scope="col">Champs du schéma</th>
</tr>
</thead>
<tbody>
{% for elt in report.table.column_comparison_info %}
<tr{% if elt[2] == 'ko' %} class="table-danger"{% endif %}>
<td>{{ elt[0]}}</td>
<td>{{ elt[1]}}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
{% else %}
<p class="text">Aucune erreur de structure</p>
{% endif %}
{# We do display body errors! #}
{% if report.table.do_display_body_errors %}
......
......@@ -3,6 +3,7 @@
Routes
"""
import copy
import itertools
import json
import subprocess
import time
......@@ -90,7 +91,7 @@ def improve_errors(errors):
return list(map(improve_err, errors))
def create_validata_report(goodtables_report, schema):
def create_validata_ui_report(validata_core_report, schema):
""" Creates an error report easier to handle and display in templates:
- only one table
- errors are contextualized
......@@ -99,7 +100,7 @@ def create_validata_report(goodtables_report, schema):
- errors are separated into "structure" and "body"
- error messages are improved
"""
report = copy.deepcopy(goodtables_report)
report = copy.deepcopy(validata_core_report)
# One table is enough
del report['table-count']
......@@ -144,6 +145,21 @@ def create_validata_report(goodtables_report, schema):
report['table']['do_display_body_errors'] = len(structure_errors) == 0 or \
all(err['code'] == 'invalid-column-delimiter' for err in structure_errors)
# Checks if a column comparison is needed
header_errors = ('missing-headers', 'extra-headers', 'wrong-headers-order')
structure_errors = [{**err, 'in_column_comp': err['code'] in header_errors} for err in structure_errors]
report['table']['errors']['structure'] = structure_errors
column_comparison_needed = any(err['in_column_comp'] == True for err in structure_errors)
column_comparison_table = []
if column_comparison_needed:
column_comparison_table = []
field_names = [f['name'] for f in schema_fields]
for t in itertools.zip_longest(headers, field_names, fillvalue=''):
status = 'ok' if t[0] == t[1] else 'ko'
column_comparison_table.append((*t, status))
report['table']['column_comparison_needed'] = column_comparison_needed
report['table']['column_comparison_info'] = column_comparison_table
# Group body errors by row id
rows = []
current_row_id = 0
......@@ -181,7 +197,7 @@ def validate(schema_code, source: ValidataSource):
""" Validate source and display report """
try:
goodtables_report = ValidatorHelper.validate(
validata_core_report = ValidatorHelper.validate(
schema_code=schema_code,
force_strings=True,
**source.get_tabulator_params(),
......@@ -193,11 +209,11 @@ def validate(schema_code, source: ValidataSource):
source_data = extract_source_data(source)
# handle report date
date_str = goodtables_report['date']
date_str = validata_core_report['date']
report_date = datetime.strptime(date_str[:date_str.find('.')], '%Y-%m-%dT%H:%M:%S')
# Enhance goodtables_report
validata_report = create_validata_report(goodtables_report, ValidatorHelper.schema(schema_code).descriptor)
# Enhance validata_core_report
validata_report = create_validata_ui_report(validata_core_report, ValidatorHelper.schema(schema_code).descriptor)
# Display report to the user
val_info = ValidatorHelper.schema_info(schema_code)
......
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