Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Validata
validata-ui
Commits
00610080
Commit
00610080
authored
Sep 28, 2018
by
Pierre Dittgen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve report to ease errors display
parent
8e52e1e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
40 deletions
+83
-40
validata_ui_next/templates/validation_report.html
validata_ui_next/templates/validation_report.html
+22
-30
validata_ui_next/views.py
validata_ui_next/views.py
+61
-10
No files found.
validata_ui_next/templates/validation_report.html
View file @
00610080
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
</div>
</div>
</div>
</div>
{% if report.
valid
%}
{% if report.
error_count == 0
%}
<h2>
La table est valide
</h2>
<h2>
La table est valide
</h2>
<p>
Aucune erreur détectée
</p>
<p>
Aucune erreur détectée
</p>
...
@@ -30,63 +30,55 @@
...
@@ -30,63 +30,55 @@
{% else %}
{% else %}
<h2>
La table est invalide
</h2>
<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 -->
<!-- table checks -->
{% if report.table.errors.structure %}
<div>
<div>
<h3>
Erreurs de tabl
e
</h3>
<h3>
Problèmes de structur
e
</h3>
<ul>
<ul>
{% for err in report['tables'][0]['errors'] %}
{% for err in report.table.errors.structure %}
{% if err.context == 'table' or err.context == 'head' %}
<li>
{{ err.message }}
</li>
<li>
<pre>
{{ err }}
</pre>
</li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
</ul>
</div>
</div>
{% endif %}
<!-- row checks -->
<!-- row checks -->
{% if report.table.errors.body %}
<div>
<div>
<h3>
Erreurs de valeurs
</h3>
<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"
>
<div
class=
"table-responsive-sm"
>
<table
class=
"table-sm table-bordered"
>
<table
class=
"table-sm table-bordered"
>
<thead
class=
"thead-light"
>
<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>
<th
scope=
"col"
>
{{ h }}
</th>
{% endfor %}
{% endfor %}
</thead>
</thead>
<!-- TODO: regrouper les erreurs par ligne ? -->
<tbody>
<tbody>
{% for row in report.table.errors.by_rows %}
<tr>
<tr>
{% for d in source_data.data_rows[err['row-number'] - 2] %}
<th>
{{ row.row_id }}
</th>
{% if loop.index == err['column-number'] %}
{% for d in source_data.data_rows[row.row_id - 2] %}
<td
class=
"table-danger"
data-toggle=
"tooltip"
title=
"{{ err.message }}"
>
{{ d }}
</td>
{% if loop.index in row.errors %}
{% else %}
<td
class=
"table-danger"
data-toggle=
"tooltip"
title=
"{{ row.errors[loop.index].message }}"
>
<td>
{{ d }}
</td>
{% else %}
{% endif %}
<td>
{% endif %}
{{ d | truncate(30) }}
</td>
{% endfor %}
{% endfor %}
</tr>
</tr>
{% endfor %}
</tbody>
</tbody>
</table>
</table>
</div>
</div>
<p
class=
"text"
>
{{ err.message }}
</p>
{% endif %}
{% endif %}
{% endfor %}
</div>
</div>
...
...
validata_ui_next/views.py
View file @
00610080
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
"""
"""
Routes
Routes
"""
"""
import
copy
import
json
import
json
import
os
import
os
from
collections
import
OrderedDict
from
collections
import
OrderedDict
...
@@ -68,14 +69,61 @@ ERR_CODE_TO_CONTEXT = dict([
...
@@ -68,14 +69,61 @@ ERR_CODE_TO_CONTEXT = dict([
])
])
def
contextualize
(
rep
or
t
):
def
contextualize
(
err
or
s
):
""" add context to errors """
""" 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
]
return
[{
**
err
,
'context'
:
ERR_CODE_TO_CONTEXT
.
get
(
err
[
'code'
],
'body'
)}
for
err
in
errors
]
report
[
'tables'
][
0
][
'errors'
]
=
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
return
report
...
@@ -83,17 +131,20 @@ def contextualize(report):
...
@@ -83,17 +131,20 @@ def contextualize(report):
def
validate
(
schema_code
,
source
,
source_type
):
def
validate
(
schema_code
,
source
,
source_type
):
""" Validate source and display report """
""" Validate source and display report """
report
=
ValidatorHelper
.
validate
(
schema_code
,
source
,
source_type
)
goodtables_report
=
ValidatorHelper
.
validate
(
schema_code
,
source
,
source_type
)
report
=
contextualize
(
report
)
validata_report
=
create_validata_report
(
goodtables_report
)
# return jsonify(better_report)
source_data
=
extract_source_data
(
source
)
source_data
=
extract_source_data
(
source
)
# Complete report
# Complete report
val_info
=
ValidatorHelper
.
schema_info
(
schema_code
)
val_info
=
ValidatorHelper
.
schema_info
(
schema_code
)
return
render_template
(
'validation_report.html'
,
title
=
'Rapport de validation'
,
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
,
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'
},
breadcrumbs
=
[{
'url'
:
url_for
(
'home'
),
'title'
:
'Accueil'
},
{
'url'
:
url_for
(
'scdl_validator'
,
val_code
=
schema_code
),
'title'
:
val_info
[
'title'
]}])
{
'url'
:
url_for
(
'scdl_validator'
,
val_code
=
schema_code
),
'title'
:
val_info
[
'title'
]}])
...
...
Write
Preview
Markdown
is supported
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