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

wip - use already translated report

parent cceab326
......@@ -22,7 +22,6 @@ from flask import abort, make_response, redirect, render_template, request, url_
from opendataschema import GitSchemaReference, by_commit_date
import validata_core
from validata_core.helpers import translate_error_code
from . import app, config, schema_catalog_registry, fetch_schema
from .ui_util import flash_error, flash_warning
......@@ -190,34 +189,6 @@ def extract_source_data(
source_header = table.header
source_rows = list(table.data_stream)
# Repair source
# tabulator_source, tabulator_options = source.build_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:
# header = ['' if v is None else v for v in row]
# else:
# rows.append(list(map(stringify, row)))
# nb_rows += 1
# 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 []]
# 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)]
# TODO: Change False into True if there are errors associated to columns
source_header_info = [(colname, False) for colname in source_header]
......@@ -246,30 +217,16 @@ def build_ui_errors(errors):
else "table",
}
# markdown to HTML (with default values for 'title' and 'content')
# Set default title if no title
# Set title
if not "title" in err:
update_keys["title"] = translate_error_code(err["code"])
# # Convert message to markdown only if no content
# # => for pre-checks errors
# if 'message' in err and not 'content' in err:
# update_keys['message'] = commonmark(err['message'])
# # Else, default message
# elif not 'message' in err or err['message'] is None:
# update_keys['message'] = '[{}]'.format(err['code'])
# # Message content
# md_content = '*content soon available*' if not 'content' in err else err['content']
# update_keys['content'] = commonmark(md_content)
update_keys["title"] = err["name"]
# Set content
content = "*content soon available*"
if "description" in err:
content = err["description"]
elif "message" in err:
if "message" in err:
content = err["message"]
elif "description" in err:
content = err["description"]
update_keys["content"] = commonmark(content)
return {**err, **update_keys}
......@@ -535,7 +492,7 @@ def create_validata_ui_report(validata_core_report, schema_dict):
for err in errors:
if "#head" in err["tags"] or "#structure" in err["tags"]:
ui_report["table"]["errors"]["structure"].append(err)
else:
elif "#body" in err["tags"]:
ui_report["table"]["errors"]["body"].append(err)
# Group body errors by row id
......@@ -543,7 +500,7 @@ def create_validata_ui_report(validata_core_report, schema_dict):
current_row_id = 0
for err in ui_report["table"]["errors"]["body"]:
if not "rowPosition" in err:
print("ERR", err)
continue
row_id = err["rowPosition"]
if row_id != current_row_id:
current_row_id = row_id
......@@ -569,12 +526,12 @@ def create_validata_ui_report(validata_core_report, schema_dict):
# and sorts by title
key_errors = ui_report["table"]["errors"][key]
key_errors_count = len(key_errors)
ct = Counter(ke["code"] for ke in key_errors)
ct = Counter(ke["name"] for ke in key_errors)
error_stats = {
"count": key_errors_count,
"count-by-code": sorted(
(translate_error_code(k), v) for k, v in ct.items()
(k, v) for k, v in ct.items()
),
}
total_errors_count += key_errors_count
......@@ -648,6 +605,7 @@ def validate(schema_instance: SchemaInstance, validata_source: ValidataResource)
if display_badge:
badge_url, badge_msg = get_badge_url_and_message(badge_info)
# Source error
source_errors = [
err
for err in validata_core_report["tables"][0]["errors"]
......@@ -669,8 +627,6 @@ def validate(schema_instance: SchemaInstance, validata_source: ValidataResource)
# create ui_report
ui_report = create_validata_ui_report(validata_core_report, schema_instance.schema)
# open("err_validata_core_report.json", "wt", encoding="utf-8").write(json.dumps(ui_report, indent=2, sort_keys=True, ensure_ascii=False))
# Display report to the user
validator_form_url = compute_validation_form_url(
schema_instance.request_parameters()
......
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