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
c8837fb1
Commit
c8837fb1
authored
Sep 27, 2018
by
Pierre Dittgen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Error contextualizing
parent
4b389be2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
3 deletions
+96
-3
validata_ui_next/templates/validation_report.html
validata_ui_next/templates/validation_report.html
+47
-3
validata_ui_next/views.py
validata_ui_next/views.py
+49
-0
No files found.
validata_ui_next/templates/validation_report.html
View file @
c8837fb1
...
...
@@ -30,17 +30,61 @@
{% else %}
<h2>
La table est invalide
</h2>
<p>
{{
len(
report['errors']
)
}} erreur(s) détectée(s)
</p>
<p>
{{ report['
tables'][0]['
errors']
|length
}} erreur(s) détectée(s)
</p>
{% endif %}
<!-- table checks -->
<div>
<h4>
Erreurs de table
</h4>
<ul>
{% for err in report['tables'][0]['errors'] %}
{% if err.context == 'table' or err.context == 'head' %}
<li>
<pre>
{{ err }}
</pre>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
<!-- row checks -->
<div>
<h4>
Erreurs de valeurs
</h4>
{% for err in report['tables'][0]['errors'] %}
{% if err.context == 'body' %}
<table>
<thead>
<th>
#
</th>
{% for h in report['tables'][0]['headers'] %}
<th>
{{ h }}
</th>
{% endfor %}
</thead>
<!-- TODO: regrouper les erreurs par ligne ? -->
<!-- Récupérer les valeurs de la ligne à partir de tabulator -->
<tbody>
<tr>
<td>
{{ err['row-number'] }}
</td>
<td
colspan=
"{{report['tables'][0]['headers']|length}}"
>
valeurs à afficher ici avec des couleurs pour souligner les cases en faute !!!
</td>
</tr>
</tbody>
</table>
{% endif %}
{% endfor %}
</div>
<pre>
{{ report_str }}
<!--
{{ report_str }}
-->
</pre>
{% endif %}
{% endblock %}
{% block footer %}
{% endblock %}
\ No newline at end of file
validata_ui_next/views.py
View file @
c8837fb1
...
...
@@ -31,10 +31,59 @@ def compute_source_preview(source, max_rows=5):
return
{
'header'
:
header
,
'data_rows'
:
rows
,
'total_rows_nb'
:
nb_rows
,
'rows_nb'
:
len
(
rows
)}
ERR_CODE_TO_CONTEXT
=
dict
([
# TODO: gets it from spec.json
(
'duplicate-header'
,
'head'
),
(
'extra-value'
,
'body'
),
(
'missing-value'
,
'body'
),
(
'source-error'
,
'table'
),
(
'schema-error'
,
'table'
),
(
'non-matching-header'
,
'head'
),
(
'blank-row'
,
'body'
),
(
'blank-header'
,
'head'
),
(
'enumerable-constraint'
,
'body'
),
(
'http-error'
,
'table'
),
(
'scheme-error'
,
'table'
),
(
'type-or-format-error'
,
'body'
),
(
'format-error'
,
'table'
),
(
'extra-header'
,
'head'
),
(
'pattern-constraint'
,
'body'
),
(
'required-constraint'
,
'body'
),
(
'missing-header'
,
'head'
),
(
'maximum-length-constraint'
,
'body'
),
(
'maximum-constraint'
,
'body'
),
(
'minimum-length-constraint'
,
'body'
),
(
'encoding-error'
,
'table'
),
(
'io-error'
,
'table'
),
(
'unique-constraint'
,
'body'
),
(
'duplicate-row'
,
'body'
),
(
'minimum-constraint'
,
'body'
),
# TODO: get it from validata_validate
(
'wrong-column-delimiter'
,
'table'
)
# Custom checks fall in default case: body
])
def
contextualize
(
report
):
""" 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
report
def
validate
(
schema_code
,
source
,
source_type
):
""" Validate source and display report """
report
=
ValidatorHelper
.
validate
(
schema_code
,
source
,
source_type
)
report
=
contextualize
(
report
)
preview
=
compute_source_preview
(
source
)
# Complete report
...
...
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