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
bbf34190
Commit
bbf34190
authored
Nov 19, 2018
by
Pierre Dittgen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add datetime in validation report
parent
876fad22
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
36 deletions
+37
-36
validata_ui/templates/validation_report.html
validata_ui/templates/validation_report.html
+1
-0
validata_ui/views.py
validata_ui/views.py
+36
-36
No files found.
validata_ui/templates/validation_report.html
View file @
bbf34190
...
...
@@ -5,6 +5,7 @@
{% endblock %}
{% block content %}
<h1>
{{ title }}
</h1>
<p
class=
"text"
>
Validation effectuée {{ validation_date }}
</p>
{# Schema info #}
<div
class=
"row"
>
...
...
validata_ui/views.py
View file @
bbf34190
...
...
@@ -19,6 +19,15 @@ from validata_ui.util import (ValidataSource, flash_error, flash_info,
from
validata_ui.validate_helper
import
ValidatorHelper
from
validata_validate
import
csv_helpers
from
validata_validate.loaders
import
custom_loaders
from
validata_ui
import
app
from
validata_ui.util
import
flash_error
,
flash_info
,
flash_success
,
flash_warning
,
ValidataSource
from
validata_ui.validate_helper
import
ValidatorHelper
from
validata_ui
import
error_messages
from
flask
import
Flask
,
jsonify
,
redirect
,
render_template
,
request
,
url_for
import
tabulator
from
io
import
BytesIO
def
extract_source_data
(
source
:
ValidataSource
,
preview_rows_nb
=
5
):
...
...
@@ -52,41 +61,34 @@ def extract_source_data(source: ValidataSource, preview_rows_nb=5):
'preview_rows'
:
rows
[:
preview_rows_nb
]}
def
improve_
errors
(
errors
):
"""
add context to errors, converts markdown content to HTML
"""
def
improve_
messages
(
errors
,
headers
,
schema
):
"""
Translates and improve error messages
"""
def
improve_err
(
err
):
""" Adds context info based on row-nb presence and converts content to HTML"""
def
error_message_default_func
(
error
,
headers
,
schema
):
""" Sets a new better error message """
error
[
'title'
]
=
error
[
'code'
]
error
[
'content'
]
=
error
.
get
(
'message'
,
'pas d
\'
information complémentaire'
)
return
error
# Context
update_keys
=
{
'context'
:
'body'
if
'row-number'
in
err
and
not
err
[
'row-number'
]
is
None
else
'table'
,
}
improved_errors
=
[]
# markdown to HTML (with default values for 'title' and 'content')
# Use default values to insure right error display in validation report
# until validata.validate finished its message migration
for
error
in
errors
:
# Set default title if no title
if
not
'title'
in
err
:
update_keys
[
'title'
]
=
'[{}]'
.
format
(
err
[
'code'
])
improve_func
=
ERROR_MESSAGE_FUNC
.
get
(
error
[
'code'
],
error_message_default_func
)
improved_errors
.
append
(
improve_func
(
error
,
headers
,
schema
))
# Convert message to markdown only if no content
# => for pre-checks errors
if
'message'
in
err
and
not
'content'
in
err
:
update_keys
[
'message'
]
=
commonmark
(
err
[
'message'
])
return
improved_errors
# Else, default message
elif
not
'message'
in
err
or
err
[
'message'
]
is
None
:
update_keys
[
'message'
]
=
'[{}]'
.
format
(
err
[
'code'
])
# Message content
md_content
=
'*content soon available*'
if
not
'content'
in
err
else
err
[
'content'
]
update_keys
[
'content'
]
=
commonmark
(
md_content
)
def
contextualize
(
errors
):
""" add context to errors """
return
{
**
err
,
**
update_keys
}
def
add_context
(
err
):
""" Adds context info based on row-nb presence """
context
=
'body'
if
'row-number'
in
err
and
not
err
[
'row-number'
]
is
None
else
'table'
return
{
**
err
,
'context'
:
context
}
return
list
(
map
(
improve_err
,
errors
))
return
list
(
map
(
add_context
,
errors
))
def
create_validata_report
(
goodtables_report
,
schema
):
...
...
@@ -122,10 +124,13 @@ def create_validata_report(goodtables_report, schema):
report
[
'table'
][
'headers_description'
]
=
[
fields_dict
[
h
][
1
]
if
h
in
fields_dict
else
'Cette colonne n
\'
est pas définie dans le schema'
for
h
in
headers
]
#
C
ontext
ualize errors and convert content from markdown to HTML
errors
=
improve_errors
(
report
[
'table'
][
'errors'
])
#
Add c
ontext
to errors
errors
=
contextualize
(
report
[
'table'
][
'errors'
])
del
report
[
'table'
][
'errors'
]
# Provide better (french) messages
errors
=
improve_messages
(
errors
,
headers
,
schema
)
# Count errors
report
[
'error_count'
]
=
len
(
errors
)
del
report
[
'error-count'
]
...
...
@@ -142,13 +147,12 @@ def create_validata_report(goodtables_report, schema):
report
[
'table'
][
'display_body_errors'
]
=
all
(
err
[
'code'
]
==
'invalid-column-delimiter'
for
err
in
report
[
'table'
][
'errors'
][
'structure'
])
# Remember number of body errors
report
[
'table'
][
'errors'
][
'body_nb_errors'
]
=
len
(
report
[
'table'
][
'errors'
][
'body'
])
# Group body errors by row id
rows
=
[]
current_row_id
=
0
for
err
in
report
[
'table'
][
'errors'
][
'body'
]:
if
not
'row-number'
in
err
:
print
(
'ERR'
,
err
)
row_id
=
err
[
'row-number'
]
del
err
[
'row-number'
]
del
err
[
'context'
]
...
...
@@ -162,9 +166,7 @@ def create_validata_report(goodtables_report, schema):
rows
[
-
1
][
'errors'
][
column_id
]
=
err
else
:
rows
[
-
1
][
'errors'
][
'row'
]
=
err
report
[
'table'
][
'errors'
][
'body_by_rows'
]
=
rows
del
report
[
'table'
][
'errors'
][
'body'
]
report
[
'table'
][
'errors'
][
'by_rows'
]
=
rows
return
report
...
...
@@ -178,8 +180,6 @@ def validate(schema_code, source: ValidataSource):
flash_error
(
'Erreur : format de fichier non supporté'
)
return
redirect
(
url_for
(
'scdl_validator'
,
val_code
=
schema_code
))
# return jsonify(goodtables_report)
source_data
=
extract_source_data
(
source
)
validata_report
=
create_validata_report
(
goodtables_report
,
ValidatorHelper
.
schema
(
schema_code
))
...
...
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