Commit b3c3e09d authored by Pierre Dittgen's avatar Pierre Dittgen

Columns table

parent fdd44444
...@@ -22,9 +22,6 @@ ...@@ -22,9 +22,6 @@
{% endif %} {% endif %}
<h1>{{ title }}</h1> <h1>{{ title }}</h1>
<p class="text">Validation effectuée {{ validation_date }}</p> <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 %} {% if print_mode %}
</div> </div>
<div class="col-md-7"> <div class="col-md-7">
...@@ -99,18 +96,48 @@ ...@@ -99,18 +96,48 @@
{{ macros.error_statistics(report) }} {{ macros.error_statistics(report) }}
<div> <h3>Problèmes de structure</h3>
<h3>Problèmes de structure</h3> {% if report.table.errors.structure %}
{% if report.table.errors.structure %} {# Non-column errors #}
{% for err in report.table.errors.structure %} {% for err in report.table.errors.structure %}
<div class="alert alert-danger"> {% if not err.in_column_comp %}
{{ err.message }} {{ err.content | safe }}
</div> {% endif %}
{% endfor %} {% endfor %}
{% else %}
<p class="text">Aucune erreur de structure</p> {# 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 %} {% endif %}
</div>
{% else %}
<p class="text">Aucune erreur de structure</p>
{% endif %}
{# We do display body errors! #} {# We do display body errors! #}
{% if report.table.do_display_body_errors %} {% if report.table.do_display_body_errors %}
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Routes Routes
""" """
import copy import copy
import itertools
import json import json
import subprocess import subprocess
import time import time
...@@ -90,7 +91,7 @@ def improve_errors(errors): ...@@ -90,7 +91,7 @@ def improve_errors(errors):
return list(map(improve_err, 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: """ Creates an error report easier to handle and display in templates:
- only one table - only one table
- errors are contextualized - errors are contextualized
...@@ -99,7 +100,7 @@ def create_validata_report(goodtables_report, schema): ...@@ -99,7 +100,7 @@ def create_validata_report(goodtables_report, schema):
- errors are separated into "structure" and "body" - errors are separated into "structure" and "body"
- error messages are improved - error messages are improved
""" """
report = copy.deepcopy(goodtables_report) report = copy.deepcopy(validata_core_report)
# One table is enough # One table is enough
del report['table-count'] del report['table-count']
...@@ -144,6 +145,21 @@ def create_validata_report(goodtables_report, schema): ...@@ -144,6 +145,21 @@ def create_validata_report(goodtables_report, schema):
report['table']['do_display_body_errors'] = len(structure_errors) == 0 or \ report['table']['do_display_body_errors'] = len(structure_errors) == 0 or \
all(err['code'] == 'invalid-column-delimiter' for err in structure_errors) 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 # Group body errors by row id
rows = [] rows = []
current_row_id = 0 current_row_id = 0
...@@ -181,7 +197,7 @@ def validate(schema_code, source: ValidataSource): ...@@ -181,7 +197,7 @@ def validate(schema_code, source: ValidataSource):
""" Validate source and display report """ """ Validate source and display report """
try: try:
goodtables_report = ValidatorHelper.validate( validata_core_report = ValidatorHelper.validate(
schema_code=schema_code, schema_code=schema_code,
force_strings=True, force_strings=True,
**source.get_tabulator_params(), **source.get_tabulator_params(),
...@@ -193,11 +209,11 @@ def validate(schema_code, source: ValidataSource): ...@@ -193,11 +209,11 @@ def validate(schema_code, source: ValidataSource):
source_data = extract_source_data(source) source_data = extract_source_data(source)
# handle report date # 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') report_date = datetime.strptime(date_str[:date_str.find('.')], '%Y-%m-%dT%H:%M:%S')
# Enhance goodtables_report # Enhance validata_core_report
validata_report = create_validata_report(goodtables_report, ValidatorHelper.schema(schema_code).descriptor) validata_report = create_validata_ui_report(validata_core_report, ValidatorHelper.schema(schema_code).descriptor)
# Display report to the user # Display report to the user
val_info = ValidatorHelper.schema_info(schema_code) 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