...
 
Commits (7)
# 0.3.4
- Improve duplicate-header errors display
- Upgrade to validata-core 0.5.4
# 0.3.3
- Adjustments in validation report display
......
......@@ -9,4 +9,4 @@ python-dotenv==0.10.1
requests==2.22.0
toml==0.10.0
tabulator==1.21.0
validata_core==0.5.3
validata_core==0.5.4
......@@ -13,7 +13,7 @@ with readme_filepath.open('rt', encoding='utf-8') as fd:
setup(
name='validata_ui',
version='0.3.3',
version='0.3.4',
description='Validata Web UI',
long_description=LONG_DESCRIPTION,
......
......@@ -7,6 +7,7 @@ import json
import logging
import subprocess
import tempfile
from collections import defaultdict
from datetime import datetime
from operator import itemgetter
from pathlib import Path
......@@ -132,12 +133,24 @@ class SchemaInstance:
def extract_source_data(source: ValidataResource, schema_descriptor, preview_rows_nb=5):
""" Computes table preview """
"""Computes table preview"""
def stringify(val):
""" Transform value into string """
"""Transform value into string"""
return '' if val is None else str(val)
def compute_duplicate_header_column_indices(source_header, duplicate_header_names):
column_name_to_indices = defaultdict(list)
for i, h in enumerate(source_header):
if h in duplicate_header_names:
column_name_to_indices[h].append(i)
col_indices = set()
for v in column_name_to_indices.values():
col_indices.update(v[1:])
return col_indices
header = None
rows = []
nb_rows = 0
......@@ -165,11 +178,21 @@ def extract_source_data(source: ValidataResource, schema_descriptor, preview_row
preview_rows_nb = min(preview_rows_nb, nb_rows)
# Computes original_headers display
# wrong headers order: display all headers as in error
if any([err.code == 'wrong-headers-order' for err in repair_report]):
source_header_info = [(h, True) for h in source_header]
# else display header error for:
# - blank-header
# - unknown-header
# - duplicate-header
else:
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]
#import ipdb; ipdb.set_trace()
duplicate_header_names = [err._message_substitutions['column-name'] for err in repair_report if err.code == 'duplicate-header']
duplicate_col_indices = compute_duplicate_header_column_indices(source_header, duplicate_header_names)
source_header_info = [(h, not h or h not in schema_field_names or i in duplicate_col_indices) for i, h in enumerate(source_header)]
return {
'source_header_info': source_header_info,
......@@ -245,13 +268,18 @@ def compute_repair_actions(structure_errors):
"""
header_errors = [err for err in error_list if err['code'] == err_code]
col_names = ["`{}`".format(err['message-data']['column-name']) for err in header_errors]
if not header_errors:
return
col_names_list = [["`{}`".format(err['message-data']['column-name']) for err in header_errors]]
if err_code == 'duplicate-header':
col_names_list.append(["`{}`".format(err['message-data']['fixed-column-name']) for err in header_errors])
if len(header_errors) == 1:
action_list.append(singular_msg_tpl.format(*[cn[0] for cn in col_names_list]))
else:
action_list.append(plural_msg_tpl.format(*[', '.join(cn) for cn in col_names_list]))
if header_errors:
if len(header_errors) == 1:
action_list.append(singular_msg_tpl.format(col_names[0]))
else:
action_list.append(plural_msg_tpl.format(', '.join(col_names)))
for err in header_errors:
error_list.remove(err)
......@@ -326,8 +354,8 @@ def compute_repair_actions(structure_errors):
# duplicate-header
handle_extra_duplicate_and_missing_errs(pending_error_list,
'duplicate-header', action_list,
"La colonne {} déjà rencontrée dans le fichier a été déplacée après les colonnes attendues",
"Les colonnes {} déjà rencontrées dans le fichier ont été déplacées après les colonnes attendues")
"La colonne {} déjà rencontrée dans le fichier a été renommée en {} et déplacée après les colonnes attendues",
"Les colonnes {} déjà rencontrées dans le fichier ont été respectivement renommées en {} et déplacées après les colonnes attendues")
# missing-header
handle_extra_duplicate_and_missing_errs(pending_error_list,
......@@ -481,11 +509,11 @@ def validate(schema_instance: SchemaInstance, source: ValidataResource):
response = requests.post(config.API_VALIDATE_ENDPOINT, data=data, files=files, headers=headers)
except requests.ConnectionError as err:
logging.exception(err)
flash_error("Erreur technique lors de la validation")
flash_error("Une erreur est survenue lors de la validation")
return redirect(url_for('home'))
if not response.ok:
flash_error("Erreur technique lors de la validation")
flash_error("Une erreur est survenue lors de la validation")
return redirect(compute_validation_form_url(schema_instance.request_parameters()))
json_response = response.json()
......