Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Validata
Validata UI
Commits
00610080
Commit
00610080
authored
Sep 28, 2018
by
Pierre Dittgen
Browse files
Improve report to ease errors display
parent
8e52e1e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
validata_ui_next/templates/validation_report.html
View file @
00610080
...
...
@@ -21,7 +21,7 @@
</div>
</div>
{% if report.
valid
%}
{% if report.
error_count == 0
%}
<h2>
La table est valide
</h2>
<p>
Aucune erreur détectée
</p>
...
...
@@ -30,63 +30,55 @@
{% else %}
<h2>
La table est invalide
</h2>
<p>
{{ report
['tables'][0]['errors']|length
}} erreur(s) détectée(s)
</p>
<p>
{{ report
.error_count
}} erreur(s) détectée(s)
</p>
<!-- table checks -->
{% if report.table.errors.structure %}
<div>
<h3>
Erreurs de tabl
e
</h3>
<h3>
Problèmes de structur
e
</h3>
<ul>
{% for err in report['tables'][0]['errors'] %}
{% if err.context == 'table' or err.context == 'head' %}
<li>
<pre>
{{ err }}
</pre>
</li>
{% endif %}
{% for err in report.table.errors.structure %}
<li>
{{ err.message }}
</li>
{% endfor %}
</ul>
</div>
{% endif %}
<!-- row checks -->
{% if report.table.errors.body %}
<div>
<h3>
Erreurs de valeurs
</h3>
{% set line = {'no': 0} %}
{% for err in report['tables'][0]['errors'] %}
{% if err.context == 'body' %}
{% if line.no != err['row-number'] %}
{% if line.update({'no': err['row-number']}) %}{% endif %}
<h4>
Ligne {{ line.no - 1}}
</h4>
{% endif %}
<div
class=
"table-responsive-sm"
>
<table
class=
"table-sm table-bordered"
>
<thead
class=
"thead-light"
>
{% for h in report['tables'][0]['headers'] %}
<th
scope=
"col"
>
Ligne
</th>
{% for h in report['table']['headers'] %}
<th
scope=
"col"
>
{{ h }}
</th>
{% endfor %}
</thead>
<!-- TODO: regrouper les erreurs par ligne ? -->
<tbody>
{% for row in report.table.errors.by_rows %}
<tr>
{% for d in source_data.data_rows[err['row-number'] - 2] %}
{% if loop.index == err['column-number'] %}
<td
class=
"table-danger"
data-toggle=
"tooltip"
title=
"{{ err.message }}"
>
{{ d }}
</td>
{% else %}
<td>
{{ d }}
</td>
{% endif %}
<th>
{{ row.row_id }}
</th>
{% for d in source_data.data_rows[row.row_id - 2] %}
{% if loop.index in row.errors %}
<td
class=
"table-danger"
data-toggle=
"tooltip"
title=
"{{ row.errors[loop.index].message }}"
>
{% else %}
<td>
{% endif %}
{{ d | truncate(30) }}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
<p
class=
"text"
>
{{ err.message }}
</p>
{% endif %}
{% endfor %}
</div>
...
...
validata_ui_next/views.py
View file @
00610080
...
...
@@ -2,6 +2,7 @@
"""
Routes
"""
import
copy
import
json
import
os
from
collections
import
OrderedDict
...
...
@@ -68,14 +69,61 @@ ERR_CODE_TO_CONTEXT = dict([
])
def
contextualize
(
rep
or
t
):
def
contextualize
(
err
or
s
):
""" add context to errors """
errors
=
report
[
'tables'
][
0
].
get
(
'errors'
)
if
errors
is
None
:
return
report
errors
=
[{
**
err
,
'context'
:
ERR_CODE_TO_CONTEXT
.
get
(
err
[
'code'
],
'body'
)}
for
err
in
errors
]
report
[
'tables'
][
0
][
'errors'
]
=
errors
return
[{
**
err
,
'context'
:
ERR_CODE_TO_CONTEXT
.
get
(
err
[
'code'
],
'body'
)}
for
err
in
errors
]
def
create_validata_report
(
goodtables_report
):
""" Creates an error report easier to handle and display in templates:
- only one table
- errors are contextualized
- error-counts is ok
- errors are grouped by lines
- errors are separated into "structure" and "body"
"""
report
=
copy
.
deepcopy
(
goodtables_report
)
# One table is enough
del
report
[
'table-count'
]
report
[
'table'
]
=
report
[
'tables'
][
0
]
del
report
[
'tables'
]
del
report
[
'table'
][
'error-count'
]
del
report
[
'table'
][
'time'
]
del
report
[
'table'
][
'valid'
]
del
report
[
'valid'
]
# Add context to errors
errors
=
contextualize
(
report
[
'table'
][
'errors'
])
del
report
[
'table'
][
'errors'
]
# Count errors
report
[
'error_count'
]
=
len
(
errors
)
del
report
[
'error-count'
]
# Then group them in 2 groups : structure and body
report
[
'table'
][
'errors'
]
=
{
'structure'
:
[],
'body'
:
[]}
for
err
in
errors
:
if
err
[
'context'
]
!=
'body'
:
report
[
'table'
][
'errors'
][
'structure'
].
append
(
err
)
else
:
report
[
'table'
][
'errors'
][
'body'
].
append
(
err
)
# and group body errors by row id
rows
=
[]
current_row_id
=
0
for
err
in
report
[
'table'
][
'errors'
][
'body'
]:
row_id
=
err
[
'row-number'
]
del
err
[
'row-number'
]
del
err
[
'context'
]
if
row_id
!=
current_row_id
:
current_row_id
=
row_id
rows
.
append
({
'row_id'
:
current_row_id
,
'errors'
:
{}})
column_id
=
err
[
'column-number'
]
del
err
[
'column-number'
]
rows
[
-
1
][
'errors'
][
column_id
]
=
err
report
[
'table'
][
'errors'
][
'by_rows'
]
=
rows
return
report
...
...
@@ -83,17 +131,20 @@ def contextualize(report):
def
validate
(
schema_code
,
source
,
source_type
):
""" Validate source and display report """
report
=
ValidatorHelper
.
validate
(
schema_code
,
source
,
source_type
)
report
=
contextualize
(
report
)
goodtables_report
=
ValidatorHelper
.
validate
(
schema_code
,
source
,
source_type
)
validata_report
=
create_validata_report
(
goodtables_report
)
# return jsonify(better_report)
source_data
=
extract_source_data
(
source
)
# Complete report
val_info
=
ValidatorHelper
.
schema_info
(
schema_code
)
return
render_template
(
'validation_report.html'
,
title
=
'Rapport de validation'
,
val_info
=
ValidatorHelper
.
schema_info
(
schema_code
),
report
=
report
,
val_info
=
ValidatorHelper
.
schema_info
(
schema_code
),
report
=
validata_
report
,
source
=
source
,
source_type
=
source_type
,
source_data
=
source_data
,
report_str
=
json
.
dumps
(
report
,
sort_keys
=
True
,
indent
=
2
),
report_str
=
json
.
dumps
(
validata_
report
,
sort_keys
=
True
,
indent
=
2
),
breadcrumbs
=
[{
'url'
:
url_for
(
'home'
),
'title'
:
'Accueil'
},
{
'url'
:
url_for
(
'scdl_validator'
,
val_code
=
schema_code
),
'title'
:
val_info
[
'title'
]}])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment