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

Use black and fix flake8 issues

parent 315cb4cd
...@@ -5,11 +5,8 @@ import copy ...@@ -5,11 +5,8 @@ import copy
import io import io
import json import json
import logging import logging
import subprocess
import tempfile
from collections import Counter from collections import Counter
from datetime import datetime from datetime import datetime
from pathlib import Path
from urllib.parse import urlencode, urljoin from urllib.parse import urlencode, urljoin
import frictionless import frictionless
...@@ -179,12 +176,12 @@ def build_ui_errors(errors): ...@@ -179,12 +176,12 @@ def build_ui_errors(errors):
# Context # Context
update_keys = { update_keys = {
"context": "body" "context": "body"
if "row-number" in err and not err["row-number"] is None if "row-number" in err and err["row-number"] is not None
else "table", else "table",
} }
# Set title # Set title
if not "title" in err: if "title" not in err:
update_keys["title"] = err["name"] update_keys["title"] = err["name"]
# Set content # Set content
...@@ -201,13 +198,13 @@ def build_ui_errors(errors): ...@@ -201,13 +198,13 @@ def build_ui_errors(errors):
def create_validata_ui_report(validata_core_report, schema_dict): def create_validata_ui_report(validata_core_report, schema_dict):
""" 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
- error-counts is ok - error-counts is ok
- errors are grouped by lines - errors are grouped by lines
- errors are separated into "structure" and "body" - errors are separated into "structure" and "body"
- error messages are improved - error messages are improved
""" """
v_report = copy.deepcopy(validata_core_report) v_report = copy.deepcopy(validata_core_report)
...@@ -267,7 +264,7 @@ def create_validata_ui_report(validata_core_report, schema_dict): ...@@ -267,7 +264,7 @@ def create_validata_ui_report(validata_core_report, schema_dict):
rows = [] rows = []
current_row_id = 0 current_row_id = 0
for err in ui_report["table"]["errors"]["body"]: for err in ui_report["table"]["errors"]["body"]:
if not "rowPosition" in err: if "rowPosition" not in err:
continue continue
row_id = err["rowPosition"] row_id = err["rowPosition"]
if row_id != current_row_id: if row_id != current_row_id:
...@@ -404,7 +401,10 @@ def validate(schema_instance: SchemaInstance, validata_resource: ValidataResourc ...@@ -404,7 +401,10 @@ def validate(schema_instance: SchemaInstance, validata_resource: ValidataResourc
if isinstance(validata_resource, URLValidataResource): if isinstance(validata_resource, URLValidataResource):
base_url = url_for("pdf_report") base_url = url_for("pdf_report")
query_string = urlencode( query_string = urlencode(
{**schema_instance.request_parameters(), "url": validata_resource.url,} {
**schema_instance.request_parameters(),
"url": validata_resource.url,
}
) )
pdf_report_url = f"{base_url}?{query_string}" pdf_report_url = f"{base_url}?{query_string}"
...@@ -520,12 +520,7 @@ def home(): ...@@ -520,12 +520,7 @@ def home():
schema_info[ schema_info[
"title" "title"
] = f"le format du schéma « {schema_info['name']} » n'est pas reconnu" ] = f"le format du schéma « {schema_info['name']} » n'est pas reconnu"
except datapackage.exceptions.ValidationError: except Exception:
schema_info["err"] = True
schema_info[
"title"
] = f"le schéma « {schema_info['name']} » comporte des erreurs"
except Exception as e:
schema_info["err"] = True schema_info["err"] = True
schema_info[ schema_info[
"title" "title"
......
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