Commit c7446b8e authored by Pierre Dittgen's avatar Pierre Dittgen

Display column title

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