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
9350a521
Commit
9350a521
authored
Nov 09, 2018
by
Pierre Dittgen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean report and adapt it to message transition
parent
58a1716e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
28 deletions
+48
-28
setup.py
setup.py
+4
-3
validata_ui/templates/table_macros.html
validata_ui/templates/table_macros.html
+1
-1
validata_ui/templates/validation_report.html
validata_ui/templates/validation_report.html
+2
-2
validata_ui/views.py
validata_ui/views.py
+41
-22
No files found.
setup.py
View file @
9350a521
...
...
@@ -25,12 +25,13 @@ setup(
include_package_data
=
True
,
install_requires
=
[
'flask'
,
'goodtables'
,
'requests'
,
'validata_validate >= 0.1, < 0.2'
,
'goodtables'
,
'
tabulator
'
,
'
commonmark
'
,
'ezodf'
,
'lxml'
'lxml'
,
'tabulator'
,
]
)
validata_ui/templates/table_macros.html
View file @
9350a521
...
...
@@ -36,7 +36,7 @@
{% endfor %}
</thead>
<tbody>
{% for row in report.table.errors.by_rows %}
{% for row in report.table.errors.
body_
by_rows %}
<tr>
{% if 'row' in row.errors %}
<th
class=
"table-danger"
data-toggle=
"popover"
title=
"{{ row.errors.row.title }}"
data-content=
"{{ row.errors.row.content }}"
>
...
...
validata_ui/templates/validation_report.html
View file @
9350a521
...
...
@@ -56,7 +56,7 @@
<!-- row checks -->
{% if report.table.errors.body %}
{% if report.table.errors.body
_nb_errors > 0
%}
{% if not report.table.display_body_errors %}
<p
class=
"text"
>
...
...
@@ -105,7 +105,7 @@
{#
{{ report.table.errors.structure|length }} erreur(s) détectée(s)
{{ report.table.errors.body
|length
}} erreur(s) détectée(s)
{{ report.table.errors.body
_nb_errors
}} erreur(s) détectée(s)
#}
{% endblock %}
\ No newline at end of file
validata_ui/views.py
View file @
9350a521
...
...
@@ -6,19 +6,19 @@ import copy
import
json
import
os
from
collections
import
OrderedDict
from
io
import
BytesIO
from
pathlib
import
Path
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
commonmark
import
commonmark
from
flask
import
Flask
,
jsonify
,
redirect
,
render_template
,
request
,
url_for
import
tabulator
from
io
import
BytesIO
import
tabulator
from
validata_ui
import
app
from
validata_ui.util
import
(
ValidataSource
,
flash_error
,
flash_info
,
flash_success
,
flash_warning
)
from
validata_ui.validate_helper
import
ValidatorHelper
from
validata_validate
import
csv_helpers
from
validata_validate.loaders
import
custom_loaders
def
extract_source_data
(
source
:
ValidataSource
,
preview_rows_nb
=
5
):
...
...
@@ -52,15 +52,30 @@ def extract_source_data(source: ValidataSource, preview_rows_nb=5):
'preview_rows'
:
rows
[:
preview_rows_nb
]}
def
contextualize
(
errors
):
""" add context to errors """
def
improve_errors
(
errors
):
""" add context to errors, converts markdown content to HTML"""
def
improve_err
(
err
):
""" Adds context info based on row-nb presence and converts content to HTML"""
# Context
update_keys
=
{
'context'
:
'body'
if
'row-number'
in
err
and
not
err
[
'row-number'
]
is
None
else
'table'
,
}
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
}
# 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
if
not
'title'
in
err
:
update_keys
[
'title'
]
=
'[{}]'
.
format
(
err
[
'code'
])
if
not
'message'
in
err
or
err
[
'message'
]
is
None
:
update_keys
[
'message'
]
=
'[{}]'
.
format
(
err
[
'code'
])
md_content
=
'*content soon available*'
if
not
'content'
in
err
else
err
[
'content'
]
update_keys
[
'content'
]
=
commonmark
(
md_content
)
return
list
(
map
(
add_context
,
errors
))
return
{
**
err
,
**
update_keys
}
return
list
(
map
(
improve_err
,
errors
))
def
create_validata_report
(
goodtables_report
,
schema
):
...
...
@@ -96,13 +111,10 @@ 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
]
#
Add c
ontext
to errors
errors
=
contextualize
(
report
[
'table'
][
'errors'
])
#
C
ontext
ualize errors and convert content from markdown to HTML
errors
=
improve_errors
(
report
[
'table'
][
'errors'
])
del
report
[
'table'
][
'errors'
]
# Provide better (french) messages
errors
=
validata_validate
.
improve_messages
(
errors
,
headers
,
schema
)
# Count errors
report
[
'error_count'
]
=
len
(
errors
)
del
report
[
'error-count'
]
...
...
@@ -119,6 +131,9 @@ 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
...
...
@@ -138,7 +153,9 @@ def create_validata_report(goodtables_report, schema):
rows
[
-
1
][
'errors'
][
column_id
]
=
err
else
:
rows
[
-
1
][
'errors'
][
'row'
]
=
err
report
[
'table'
][
'errors'
][
'by_rows'
]
=
rows
report
[
'table'
][
'errors'
][
'body_by_rows'
]
=
rows
del
report
[
'table'
][
'errors'
][
'body'
]
return
report
...
...
@@ -152,6 +169,8 @@ 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