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
0f20ef37
Commit
0f20ef37
authored
Nov 30, 2018
by
Christophe Benz
Browse files
On PDF error, don't display system error, redirect to schema page
parent
4710cd29
Changes
1
Hide whitespace changes
Inline
Side-by-side
validata_ui/views.py
View file @
0f20ef37
...
@@ -265,16 +265,16 @@ def validators():
...
@@ -265,16 +265,16 @@ def validators():
@
app
.
route
(
'/pdf/<val_code>'
)
@
app
.
route
(
'/pdf/<val_code>'
)
def
pdf_report
(
val_code
):
def
pdf_report
(
val_code
):
"""PDF report generation"""
"""PDF report generation"""
err_prefix
=
'Erreur de génération du rapport PDF
:
'
err_prefix
=
'Erreur de génération du rapport PDF'
if
not
ValidatorHelper
.
schema_exist
(
val_code
):
if
not
ValidatorHelper
.
schema_exist
(
val_code
):
flash_error
(
err_prefix
+
'schéma inconnu'
)
flash_error
(
err_prefix
+
'
:
schéma inconnu'
)
return
redirect
(
url_for
(
'
home'
))
return
redirect
(
url_for
(
'
scdl_validator'
,
val_code
=
val_code
))
url_param
=
request
.
args
.
get
(
'url'
)
url_param
=
request
.
args
.
get
(
'url'
)
if
not
url_param
:
if
not
url_param
:
flash_error
(
err_prefix
+
'url
non fournie'
)
flash_error
(
err_prefix
+
': URL
non fournie'
)
return
redirect
(
url_for
(
'
home'
))
return
redirect
(
url_for
(
'
scdl_validator'
,
val_code
=
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
))
...
@@ -286,10 +286,11 @@ def pdf_report(val_code):
...
@@ -286,10 +286,11 @@ def pdf_report(val_code):
'--print-to-pdf={}'
.
format
(
str
(
tmp_pdf_report
)),
validation_url
]
'--print-to-pdf={}'
.
format
(
str
(
tmp_pdf_report
)),
validation_url
]
result
=
subprocess
.
run
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
result
=
subprocess
.
run
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
if
result
.
returncode
!=
0
:
if
result
.
returncode
!=
0
:
flash_error
(
err_prefix
+
result
.
stdout
)
flash_error
(
err_prefix
)
log
.
error
(
"Command %r returned an error: %r"
,
cmd
,
result
.
stdout
.
decode
(
'utf-8'
))
if
tmp_pdf_report
.
exists
():
if
tmp_pdf_report
.
exists
():
tmp_pdf_report
.
unlink
()
tmp_pdf_report
.
unlink
()
return
redirect
(
url_for
(
'
home'
))
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
.
open
(
'rb'
).
read
())
response
.
headers
.
set
(
'Content-disposition'
,
'attachment'
,
filename
=
'report.pdf'
)
response
.
headers
.
set
(
'Content-disposition'
,
'attachment'
,
filename
=
'report.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