Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Validata
validata-ui
Commits
e9887775
Commit
e9887775
authored
Nov 30, 2018
by
Christophe Benz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use tempfile and read_bytes
parent
0f20ef37
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
validata_ui/views.py
validata_ui/views.py
+7
-3
No files found.
validata_ui/views.py
View file @
e9887775
...
...
@@ -5,7 +5,9 @@
import
copy
import
itertools
import
json
import
logging
import
subprocess
import
tempfile
import
time
from
datetime
import
datetime
from
io
import
BytesIO
...
...
@@ -27,6 +29,8 @@ from validata_ui.validate_helper import ValidatorHelper
MonkeyPatch
.
patch_fromisoformat
()
log
=
logging
.
getLogger
(
__name__
)
def
extract_source_data
(
source
:
ValidataSource
,
preview_rows_nb
=
5
):
""" Computes table preview """
...
...
@@ -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
),
quote_plus
(
url_param
))
#
temp
orary pdf_report.pdf filename
tmp_pdf_report
=
Path
(
'/
tmp
'
)
/
'validata_{}_{}_pdf_report.pdf'
.
format
(
val_code
,
str
(
time
.
time
())
)
with
temp
file
.
NamedTemporaryFile
(
prefix
=
'validata_{}_report_'
.
format
(
val_code
),
suffix
=
'.pdf'
)
as
tmpfile
:
tmp_pdf_report
=
Path
(
tmp
file
.
name
)
cmd
=
[
'chromium'
,
'--headless'
,
'--disable-gpu'
,
'--print-to-pdf={}'
.
format
(
str
(
tmp_pdf_report
)),
validation_url
]
...
...
@@ -292,7 +296,7 @@ def pdf_report(val_code):
tmp_pdf_report
.
unlink
()
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-type'
,
'application/pdf'
)
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