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
e9887775
Commit
e9887775
authored
Nov 30, 2018
by
Christophe Benz
Browse files
Use tempfile and read_bytes
parent
0f20ef37
Changes
1
Hide whitespace changes
Inline
Side-by-side
validata_ui/views.py
View file @
e9887775
...
@@ -5,7 +5,9 @@
...
@@ -5,7 +5,9 @@
import
copy
import
copy
import
itertools
import
itertools
import
json
import
json
import
logging
import
subprocess
import
subprocess
import
tempfile
import
time
import
time
from
datetime
import
datetime
from
datetime
import
datetime
from
io
import
BytesIO
from
io
import
BytesIO
...
@@ -27,6 +29,8 @@ from validata_ui.validate_helper import ValidatorHelper
...
@@ -27,6 +29,8 @@ from validata_ui.validate_helper import ValidatorHelper
MonkeyPatch
.
patch_fromisoformat
()
MonkeyPatch
.
patch_fromisoformat
()
log
=
logging
.
getLogger
(
__name__
)
def
extract_source_data
(
source
:
ValidataSource
,
preview_rows_nb
=
5
):
def
extract_source_data
(
source
:
ValidataSource
,
preview_rows_nb
=
5
):
""" Computes table preview """
""" Computes table preview """
...
@@ -279,8 +283,8 @@ def pdf_report(val_code):
...
@@ -279,8 +283,8 @@ def pdf_report(val_code):
validation_url
=
'{}?input=url&print=true&url={}'
.
format
(
url_for
(
'scdl_validator'
,
val_code
=
val_code
,
_external
=
True
),
validation_url
=
'{}?input=url&print=true&url={}'
.
format
(
url_for
(
'scdl_validator'
,
val_code
=
val_code
,
_external
=
True
),
quote_plus
(
url_param
))
quote_plus
(
url_param
))
#
temp
orary pdf_report.pdf filename
with
temp
file
.
NamedTemporaryFile
(
prefix
=
'validata_{}_report_'
.
format
(
val_code
),
suffix
=
'.pdf'
)
as
tmpfile
:
tmp_pdf_report
=
Path
(
'/
tmp
'
)
/
'validata_{}_{}_pdf_report.pdf'
.
format
(
val_code
,
str
(
time
.
time
())
)
tmp_pdf_report
=
Path
(
tmp
file
.
name
)
cmd
=
[
'chromium'
,
'--headless'
,
'--disable-gpu'
,
cmd
=
[
'chromium'
,
'--headless'
,
'--disable-gpu'
,
'--print-to-pdf={}'
.
format
(
str
(
tmp_pdf_report
)),
validation_url
]
'--print-to-pdf={}'
.
format
(
str
(
tmp_pdf_report
)),
validation_url
]
...
@@ -292,7 +296,7 @@ def pdf_report(val_code):
...
@@ -292,7 +296,7 @@ def pdf_report(val_code):
tmp_pdf_report
.
unlink
()
tmp_pdf_report
.
unlink
()
return
redirect
(
url_for
(
'scdl_validator'
,
val_code
=
val_code
))
return
redirect
(
url_for
(
'scdl_validator'
,
val_code
=
val_code
))
response
=
make_response
(
tmp_pdf_report
.
open
(
'rb'
).
read
())
response
=
make_response
(
tmp_pdf_report
.
read_bytes
())
response
.
headers
.
set
(
'Content-disposition'
,
'attachment'
,
filename
=
'report.pdf'
)
response
.
headers
.
set
(
'Content-disposition'
,
'attachment'
,
filename
=
'report.pdf'
)
response
.
headers
.
set
(
'Content-type'
,
'application/pdf'
)
response
.
headers
.
set
(
'Content-type'
,
'application/pdf'
)
response
.
headers
.
set
(
'Content-length'
,
tmp_pdf_report
.
stat
().
st_size
)
response
.
headers
.
set
(
'Content-length'
,
tmp_pdf_report
.
stat
().
st_size
)
...
...
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