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
ed69148a
Commit
ed69148a
authored
Sep 27, 2018
by
Pierre Dittgen
Browse files
First display of table preview
parent
62c085e8
Changes
4
Show whitespace changes
Inline
Side-by-side
setup.py
View file @
ed69148a
...
...
@@ -27,6 +27,8 @@ setup(
'flask'
,
'requests'
,
'ujson'
,
'validata_validate'
'validata_validate'
,
'goodtables'
,
'tabulator'
]
)
validata_ui_next/templates/validation_report.html
0 → 100644
View file @
ed69148a
{% extends "base.html" %}
{% block title %}{{ title }}{% endblock %}
{% block head %}
{{ super() }}
{% endblock %}
{% block content %}
<h1>
{{ title }}
</h1>
<div
class=
"card bg-faded"
style=
"width: 30rem;"
>
<div
class=
"card-body"
>
<h5
class=
"card-title"
>
Schéma {{ val_info.code }}
<span
class=
"badge badge-primary"
>
{{ val_info.version }}
</span>
</h5>
<h6
class=
"card-subtitle mb-2 text-muted"
>
{{ val_info.description }}
</h6>
<p
class=
"text"
>
{% if source_type == 'file' %}Fichier{% endif %}
{% if source_type == 'url' %}URL{% endif %}
à valider : {{ source }}
</p>
</div>
</div>
<h2>
Aperçu
</h2>
<table
class=
"table table-striped table-bordered"
>
<thead>
<tr>
{% for col in preview.header %}
<th
scope=
"col"
>
{{ col }}
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in preview.data_rows %}
<tr>
{% for val in row %}
<td>
{{ val }}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% if report.valid %}
<h2>
La table est valide
</h2>
<p>
Aucune erreur détectée
</p>
{% else %}
<h2>
La table est invalide
</h2>
<p>
{{ report['error-count'] }} erreur(s) détectée(s)
</p>
{% endif %}
<pre>
{{ report_str }}
</pre>
{% endblock %}
{% block footer %}
{% endblock %}
\ No newline at end of file
validata_ui_next/validate.py
View file @
ed69148a
...
...
@@ -75,7 +75,6 @@ class ValidatorHelper:
# All keys but schema* and custom_checks*
d2
=
{
k
:
v
for
k
,
v
in
cls
.
schema_dict
[
schema_code
].
items
()
if
not
k
.
startswith
(
'schema'
)
and
not
k
.
startswith
(
'custom_checks'
)}
print
(
'D2 ='
,
d2
)
return
{
**
d1
,
'code'
:
schema_code
,
**
d2
}
...
...
validata_ui_next/views.py
View file @
ed69148a
...
...
@@ -12,12 +12,35 @@ from validata_ui_next.util import flash_error, flash_info, flash_success, flash_
from
validata_ui_next.validate
import
ValidatorHelper
from
flask
import
Flask
,
jsonify
,
redirect
,
render_template
,
request
,
url_for
import
tabulator
def
compute_source_preview
(
source
,
max_rows
=
5
):
""" Computes table preview """
header
=
None
nb_rows
=
0
rows
=
[]
with
tabulator
.
Stream
(
source
)
as
stream
:
for
row
in
stream
:
if
header
is
None
:
header
=
row
else
:
rows
.
append
(
row
)
if
len
(
rows
)
==
max_rows
:
break
return
{
'header'
:
header
,
'data_rows'
:
rows
}
def
validate
(
schema_code
,
source
,
source_type
):
""" Validate source and display report """
def
validate
(
schema_code
,
source
,
res
_type
)
:
report
=
ValidatorHelper
.
validate
(
schema_code
,
source
,
res_typ
e
)
report
=
ValidatorHelper
.
validate
(
schema_code
,
source
,
source
_type
)
preview
=
compute_source_preview
(
sourc
e
)
return
jsonify
(
report
)
return
render_template
(
'validation_report.html'
,
title
=
'Rapport de validation'
,
val_info
=
ValidatorHelper
.
schema_info
(
schema_code
),
report
=
report
,
source
=
source
,
source_type
=
source_type
,
preview
=
preview
,
report_str
=
json
.
dumps
(
report
,
sort_keys
=
True
,
indent
=
2
))
# Routes
...
...
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