Skip to content

Commit

Permalink
fix: BC in c2cgeoportal proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
tonio committed Jan 6, 2021
1 parent ecb1f66 commit 561ce8d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions geoportal/geoportailv3_geoportal/views/luxprintproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from pyramid.view import view_config
from pyramid.httpexceptions import HTTPUnauthorized, HTTPInternalServerError
from pyramid.httpexceptions import HTTPNotFound
from pyramid.response import Response

from PyPDF2 import PdfFileMerger
import weasyprint
Expand Down Expand Up @@ -152,7 +153,8 @@ def lux_get_thumbnail(self):
print_url = valid_print_urls[random.randint(0, len(valid_print_urls) - 1)]
else:
print_url = self.config["print_url"]
resp, content = self._proxy("%s/buildreport.png" % (print_url), params="", method="POST", body=str.encode(dumps(spec)), headers={"Referer": "http://print.geoportail.lu/"})
resp = self._proxy("%s/buildreport.png" % (print_url), params="", method="POST", body=str.encode(dumps(spec)), headers={"Referer": "http://print.geoportail.lu/"})
content = resp.content
resp["content-disposition"] = "filename=%s.png" % (str(layer_id))

return self._build_response(
Expand Down Expand Up @@ -367,9 +369,10 @@ def lux_report_get(self):
if job is None:
return HTTPNotFound()
try:
resp, content = self._proxy("%s/report/%s" % (
resp = self._proxy("%s/report/%s" % (
job.print_url, ref
))
content = resp.content

attributes = json.loads(job.spec)["attributes"]
is_pdf = json.loads(job.spec)["format"] == "pdf"
Expand Down Expand Up @@ -489,15 +492,15 @@ def lux_report_get(self):
content = content.getvalue()

DBSession.delete(job)
if is_pdf:
resp["content-disposition"] =\
"attachment; filename=%s.pdf" % (str(print_title))
else:
resp["content-disposition"] =\
"attachment; filename=%s.png" % (str(print_title))
headers = resp.headers
headers.update({
"content-disposition": "attachment; filename=%s.%s" % (str(print_title), 'pdf' if is_pdf else 'png')
})

response = Response(content, status=resp.status_code, headers=headers)

return self._build_response(
resp, content, NO_CACHE, "print"
response, content, NO_CACHE, "print"
)
except Exception as e:
log.exception(e)
Expand Down

0 comments on commit 561ce8d

Please sign in to comment.