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
f41c9321
Commit
f41c9321
authored
Jun 03, 2019
by
Pierre Dittgen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDF report is ok now
parent
84c0a3a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
23 deletions
+20
-23
validata_ui/templates/validation_report.html
validata_ui/templates/validation_report.html
+6
-4
validata_ui/views.py
validata_ui/views.py
+14
-19
No files found.
validata_ui/templates/validation_report.html
View file @
f41c9321
...
...
@@ -36,7 +36,7 @@
{% endif %}
{% if source.type == 'url' %}
<p
class=
"hidden-print"
>
<a
href=
"{{ url_for('pdf_report'
, val_code=val_info.
code
)
}}
?
url={{source.name|urlencode}}"
target=
"_blank"
>
<a
href=
"{{ url_for('pdf_report'
) }}?schema={{schema_url|urlen
code}}
&
url={{source.name|urlencode}}"
target=
"_blank"
>
Télécharger en PDF
</a>
</p>
...
...
@@ -47,7 +47,7 @@
<div
class=
"card bg-faded"
>
<div
class=
"card-body"
>
<h5
class=
"card-title"
>
Schéma
{{ val_info.code }}
Schéma
<span
class=
"badge badge-primary"
>
{{ val_info.version }}
</span>
</h5>
<h6
class=
"card-subtitle mb-2 text-muted"
>
{{ val_info.description }}
</h6>
...
...
@@ -62,11 +62,13 @@
</p>
{% endif %}
<p>
<a
href=
"{{
val_info.doc
_url }}"
target=
"_blank"
class=
"card-link"
>
Documentation
</a>
<a
href=
"{{
schema
_url }}"
target=
"_blank"
class=
"card-link"
>
{{ schema_url }}
</a>
</p>
<hr
/>
<div>
Fichier traité :
<h5
class=
"card-title"
>
Fichier traité
</h5>
{% if source_type == 'file' %}
{{ source.name }}
{% endif %}
...
...
validata_ui/views.py
View file @
f41c9321
...
...
@@ -43,12 +43,6 @@ def extract_source_data(source: ValidataSource, preview_rows_nb=5):
rows
=
[]
nb_rows
=
0
# if source.scheme == 'file':
# source.scheme = 'bytes'
import
ipdb
ipdb
.
set_trace
()
options
=
{}
if
source
.
format
==
"csv"
:
options
[
'delimiter'
]
=
csv_helpers
.
detect_dialect
(
source
.
source
,
format
=
source
.
format
,
scheme
=
source
.
scheme
,
...
...
@@ -300,6 +294,7 @@ def validate(schema_url, source: ValidataSource):
# Display report to the user
return
render_template
(
'validation_report.html'
,
title
=
'Rapport de validation'
,
val_info
=
{},
report
=
validata_report
,
schema_url
=
schema_url
,
validation_date
=
report_datetime
.
strftime
(
'le %d/%m/%Y à %Hh%M'
),
source
=
source
,
source_type
=
source
.
type
,
source_data
=
source_data
,
print_mode
=
request
.
args
.
get
(
'print'
,
'false'
)
==
'true'
,
...
...
@@ -352,24 +347,25 @@ def validators():
return
redirect
(
url_for
(
'home'
))
@
app
.
route
(
'/pdf
/<val_code>
'
)
def
pdf_report
(
val_code
):
@
app
.
route
(
'/pdf'
)
def
pdf_report
():
"""PDF report generation"""
err_prefix
=
'Erreur de génération du rapport PDF'
if
not
ValidatorHelper
.
schema_exist
(
val_code
):
flash_error
(
err_prefix
+
': schéma inconnu'
)
return
redirect
(
url_for
(
'scdl_validator'
,
val_code
=
val_code
))
url_param
=
request
.
args
.
get
(
'url'
)
if
not
url_param
:
flash_error
(
err_prefix
+
': URL non fournie'
)
return
redirect
(
url_for
(
'scdl_validator'
,
val_code
=
val_code
))
return
redirect
(
url_for
(
'home'
))
schema_param
=
request
.
args
.
get
(
'schema'
)
if
not
schema_param
:
flash_error
(
err_prefix
+
': URL de schema non fournie'
)
return
redirect
(
url_for
(
'home'
))
validation_url
=
'{}?input=url&print=true&url={}'
.
format
(
url_for
(
'
scdl
_validator'
,
val_code
=
val_code
,
_external
=
True
),
quote_plus
(
url_param
))
validation_url
=
'{}?input=url&print=true&url={}
&schema={}
'
.
format
(
url_for
(
'
custom
_validator'
,
_external
=
True
),
quote_plus
(
url_param
)
,
quote_plus
(
schema_param
)
)
with
tempfile
.
NamedTemporaryFile
(
prefix
=
'validata_{}_report_'
.
format
(
val_code
),
suffix
=
'.pdf'
)
as
tmpfile
:
with
tempfile
.
NamedTemporaryFile
(
prefix
=
'validata_{}_report_'
.
format
(
datetime
.
now
().
timestamp
()
),
suffix
=
'.pdf'
)
as
tmpfile
:
tmp_pdf_report
=
Path
(
tmpfile
.
name
)
cmd
=
[
'chromium'
,
'--headless'
,
'--disable-gpu'
,
...
...
@@ -380,10 +376,9 @@ def pdf_report(val_code):
log
.
error
(
"Command %r returned an error: %r"
,
cmd
,
result
.
stdout
.
decode
(
'utf-8'
))
if
tmp_pdf_report
.
exists
():
tmp_pdf_report
.
unlink
()
return
redirect
(
url_for
(
'
scdl_validator'
,
val_code
=
val_code
))
return
redirect
(
url_for
(
'
home'
))
pdf_filename
=
'Rapport de validation {} {}.pdf'
.
format
(
val_code
,
datetime
.
now
().
strftime
(
'%d-%m-%Y %Hh%M'
))
pdf_filename
=
'Rapport de validation {}.pdf'
.
format
(
datetime
.
now
().
strftime
(
'%d-%m-%Y %Hh%M'
))
response
=
make_response
(
tmp_pdf_report
.
read_bytes
())
response
.
headers
.
set
(
'Content-disposition'
,
'attachment'
,
filename
=
pdf_filename
)
response
.
headers
.
set
(
'Content-type'
,
'application/pdf'
)
...
...
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