Commit d661d89e authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Source file header display

parent 642a00e5
......@@ -114,6 +114,19 @@
{% endif %}
{% if report.repair_actions %}
<div class="mx-4 mb-4">
<div class="table-responsive">
<p>En-têtes du fichier source</p>
<table class="table table-striped table-bordered table-sm table-hover">
{% for h, err in source_data.source_header_info %}
<th{% if err %} class="table-danger"{% endif %}>{{ h }}</th>
{% endfor %}
{% endif %}
{# Display body errors #}
<div class="mx-4">
{% if report.table.errors.body %}
......@@ -144,7 +144,18 @@ def extract_source_data(source: ValidataResource, schema_descriptor, preview_row
nb_rows = 0
tabulator_source, tabulator_options = source.build_tabulator_stream_args()
fixed_source, _ = repair(tabulator_source, schema_descriptor, **tabulator_options)
# Gets original source, only to get headers
source_header = None
with tabulator.Stream(tabulator_source, **tabulator_options) as stream:
for row in stream:
if source_header is None:
source_header = ['' if v is None else v for v in row]
# Repair source
tabulator_source, tabulator_options = source.build_tabulator_stream_args()
fixed_source, repair_report = repair(tabulator_source, schema_descriptor, **tabulator_options)
with tabulator.Stream(fixed_source, {**tabulator_options, 'scheme': 'stream', 'format': 'inline'}) as stream:
for row in stream:
if header is None:
......@@ -153,11 +164,22 @@ def extract_source_data(source: ValidataResource, schema_descriptor, preview_row
rows.append(list(map(stringify, row)))
nb_rows += 1
preview_rows_nb = min(preview_rows_nb, nb_rows)
return {'header': header,
'rows_nb': nb_rows,
'data_rows': rows,
'preview_rows_nb': preview_rows_nb,
'preview_rows': rows[:preview_rows_nb]}
# Computes original_headers display
if any([err.code == 'wrong-headers-order' for err in repair_report]):
source_header_info = [(h, True) for h in source_header]
schema_field_names = [f['name'] for f in schema_descriptor.get('fields') or []]
source_header_info = [(h, not h or h not in schema_field_names) for h in source_header]
return {
'source_header_info': source_header_info,
'header': header,
'rows_nb': nb_rows,
'data_rows': rows,
'preview_rows_nb': preview_rows_nb,
'preview_rows': rows[:preview_rows_nb]
def improve_errors(errors):
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