Commit 8b6416b4 authored by Pierre Dittgen's avatar Pierre Dittgen

Introducing entire row errors display (in french)

parent fdb64d1a
...@@ -63,7 +63,12 @@ ...@@ -63,7 +63,12 @@
<tbody> <tbody>
{% for row in report.table.errors.by_rows %} {% for row in report.table.errors.by_rows %}
<tr> <tr>
{% if 'row' in row.errors %}
<th class="table-danger data-toggle=" tooltip" title="{{ row.errors.row.message }}">{{ row.row_id
}}</th>
{% else %}
<th>{{ row.row_id }}</th> <th>{{ row.row_id }}</th>
{% endif %}
{% for d in source_data.data_rows[row.row_id - 2] %} {% for d in source_data.data_rows[row.row_id - 2] %}
{% if loop.index in row.errors %} {% if loop.index in row.errors %}
<td class="table-danger" data-toggle="tooltip" title="[{{row.errors[loop.index].code}}] {{ row.errors[loop.index].message }}"> <td class="table-danger" data-toggle="tooltip" title="[{{row.errors[loop.index].code}}] {{ row.errors[loop.index].message }}">
......
...@@ -76,6 +76,28 @@ ERR_CODE_TO_CONTEXT = dict([ ...@@ -76,6 +76,28 @@ ERR_CODE_TO_CONTEXT = dict([
]) ])
def improve_messages(errors):
""" Translates and improve error messages """
def update_message(error, new_message):
""" set a new error message """
# Stores previous message if exists
if 'message' in error:
error['_original_message'] = error['message']
error['message'] = new_message
for error in errors:
if error['code'] == 'blank-row':
update_message(error, 'la ligne {} est vide'.format(error['row-number']))
elif error['code'] == 'duplicate-row':
update_message(error, 'la ligne {} est identique à la précédente'.format(error['row-number']))
# Return updated error list
return errors
def contextualize(errors): def contextualize(errors):
""" add context to errors """ """ add context to errors """
...@@ -89,6 +111,7 @@ def create_validata_report(goodtables_report): ...@@ -89,6 +111,7 @@ def create_validata_report(goodtables_report):
- 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
""" """
report = copy.deepcopy(goodtables_report) report = copy.deepcopy(goodtables_report)
...@@ -100,11 +123,19 @@ def create_validata_report(goodtables_report): ...@@ -100,11 +123,19 @@ def create_validata_report(goodtables_report):
del report['table']['time'] del report['table']['time']
del report['table']['valid'] del report['table']['valid']
del report['valid'] del report['valid']
# 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']['headers'])
# Add context to errors # Add context to errors
errors = contextualize(report['table']['errors']) errors = contextualize(report['table']['errors'])
del report['table']['errors'] del report['table']['errors']
# Provide better (french) messages
errors = improve_messages(errors)
# Count errors # Count errors
report['error_count'] = len(errors) report['error_count'] = len(errors)
del report['error-count'] del report['error-count']
...@@ -121,20 +152,19 @@ def create_validata_report(goodtables_report): ...@@ -121,20 +152,19 @@ def create_validata_report(goodtables_report):
rows = [] rows = []
current_row_id = 0 current_row_id = 0
for err in report['table']['errors']['body']: for err in report['table']['errors']['body']:
if not 'column-number' in err:
# TODO: handle blank row
print("No column-number problem", err)
continue
row_id = err['row-number'] row_id = err['row-number']
del err['row-number'] del err['row-number']
del err['context'] del err['context']
if row_id != current_row_id: if row_id != current_row_id:
current_row_id = row_id current_row_id = row_id
rows.append({'row_id': current_row_id, 'errors': {}}) rows.append({'row_id': current_row_id, 'errors': {}})
column_id = err['column-number']
del err['column-number'] column_id = err.get('column-number')
rows[-1]['errors'][column_id] = err if column_id is not None:
del err['column-number']
rows[-1]['errors'][column_id] = err
else:
rows[-1]['errors']['row'] = err
report['table']['errors']['by_rows'] = rows report['table']['errors']['by_rows'] = rows
return report return 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