From c7446b8e0c2b89215b7ea84faea4ce0a0a253b69 Mon Sep 17 00:00:00 2001 From: Pierre Dittgen Date: Tue, 2 Oct 2018 15:29:10 +0200 Subject: [PATCH] Display column title --- validata_ui_next/templates/validation_report.html | 6 +++--- validata_ui_next/validate_helper.py | 7 +++++++ validata_ui_next/views.py | 13 +++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/validata_ui_next/templates/validation_report.html b/validata_ui_next/templates/validation_report.html index e356940..787336f 100644 --- a/validata_ui_next/templates/validation_report.html +++ b/validata_ui_next/templates/validation_report.html @@ -64,8 +64,8 @@ - {% for h in report['table']['headers'] %} - + {% for h in report.table.headers %} + {% endfor %} @@ -126,4 +126,4 @@ }) }) -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/validata_ui_next/validate_helper.py b/validata_ui_next/validate_helper.py index 17283c9..1efb5aa 100644 --- a/validata_ui_next/validate_helper.py +++ b/validata_ui_next/validate_helper.py @@ -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 """ diff --git a/validata_ui_next/views.py b/validata_ui_next/views.py index 1e090aa..b1e1fa1 100644 --- a/validata_ui_next/views.py +++ b/validata_ui_next/views.py @@ -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) -- GitLab
1{{ h }}{{ h }}