Commit c7446b8e authored by Pierre Dittgen's avatar Pierre Dittgen

Display column title

parent f6558b1e
......@@ -64,8 +64,8 @@
<table class="table-sm table-bordered">
<thead class="thead-light">
<th scope="col">1</th>
{% for h in report['table']['headers'] %}
<th scope="col">{{ h }}</th>
{% for h in report.table.headers %}
<th scope="col" data-toggle="tooltip" title="{{ report.table.headers_title[loop.index - 1]}}">{{ h }}</th>
{% endfor %}
</thead>
<tbody>
......@@ -126,4 +126,4 @@
})
})
</script>
{% endblock %}
\ No newline at end of file
{% endblock %}
......@@ -75,6 +75,13 @@ class ValidatorHelper:
return {**d1, 'code': schema_code, **d2}
@classmethod
def schema_fields(cls, schema_code):
""" Return schema fields from schema code """
if not cls.schema_exist(schema_code):
return None
return cls.schema_dict[schema_code]['schema']['fields']
@classmethod
def schema_info_list(cls):
""" Computes and return schema info list """
......
......@@ -122,7 +122,7 @@ def contextualize(errors):
return [{**err, 'context': ERR_CODE_TO_CONTEXT.get(err['code'], 'body')} for err in errors]
def create_validata_report(goodtables_report):
def create_validata_report(goodtables_report, schema_fields=[]):
""" Creates an error report easier to handle and display in templates:
- only one table
- errors are contextualized
......@@ -144,8 +144,13 @@ def create_validata_report(goodtables_report):
# use _ instead of - to ease information picking in jinja2 template
report['table']['row_count'] = report['table']['row-count']
# Shortcut
report['table']['col_count'] = len(report['table'].get('headers', []))
# Handy col_count info
headers = report['table'].get('headers', [])
report['table']['col_count'] = len(headers)
# Headers title
fields_dict = {f['name']: f['title'] for f in schema_fields}
report['table']['headers_title'] = [fields_dict.get(h, '?? colonne inconnue dans le schéma ??') for h in headers]
# Add context to errors
errors = contextualize(report['table']['errors'])
......@@ -195,7 +200,7 @@ def validate(schema_code, source: ValidataSource):
source_data = extract_source_data(source)
validata_report = create_validata_report(goodtables_report)
validata_report = create_validata_report(goodtables_report, ValidatorHelper.schema_fields(schema_code))
# return jsonify(validata_report)
......
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