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
4b389be2
Commit
4b389be2
authored
Sep 27, 2018
by
Pierre Dittgen
Browse files
Externalize table preview
parent
6fd32a87
Changes
3
Show whitespace changes
Inline
Side-by-side
validata_ui_next/templates/table_preview.html
0 → 100644
View file @
4b389be2
<p
class=
"text"
>
Affichage de {{ preview.rows_nb }} lignes sur {{ preview.total_rows_nb }} au total
</p>
<div
class=
"table-responsive"
>
<table
class=
"table table-striped table-bordered table-sm table-hover"
>
<thead
class=
"thead-light"
>
<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>
</div>
\ No newline at end of file
validata_ui_next/templates/validation_report.html
View file @
4b389be2
...
...
@@ -21,33 +21,17 @@
</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>
{% include 'table_preview.html' %}
{% else %}
<h2>
La table est invalide
</h2>
<p>
{{ report['error-count'] }} erreur(s) détectée(s)
</p>
<p>
{{ len(report['errors']) }} erreur(s) détectée(s)
</p>
{% endif %}
...
...
validata_ui_next/views.py
View file @
4b389be2
...
...
@@ -19,15 +19,16 @@ def compute_source_preview(source, max_rows=5):
""" Computes table preview """
header
=
None
rows
=
[]
nb_rows
=
0
with
tabulator
.
Stream
(
source
)
as
stream
:
for
row
in
stream
:
if
header
is
None
:
header
=
row
else
:
nb_rows
+=
1
if
len
(
rows
)
<=
max_rows
:
rows
.
append
(
row
)
if
len
(
rows
)
==
max_rows
:
break
return
{
'header'
:
header
,
'data_rows'
:
rows
}
return
{
'header'
:
header
,
'data_rows'
:
rows
,
'total_rows_nb'
:
nb_rows
,
'rows_nb'
:
len
(
rows
)}
def
validate
(
schema_code
,
source
,
source_type
):
...
...
@@ -36,10 +37,14 @@ def validate(schema_code, source, source_type):
report
=
ValidatorHelper
.
validate
(
schema_code
,
source
,
source_type
)
preview
=
compute_source_preview
(
source
)
# Complete report
val_info
=
ValidatorHelper
.
schema_info
(
schema_code
)
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
))
report_str
=
json
.
dumps
(
report
,
sort_keys
=
True
,
indent
=
2
),
breadcrumbs
=
[{
'url'
:
url_for
(
'home'
),
'title'
:
'Accueil'
},
{
'url'
:
url_for
(
'scdl_validator'
,
val_code
=
schema_code
),
'title'
:
val_info
[
'title'
]}])
# 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