When exporting project raise error if export is not possible

This commit is contained in:
Julien Duponchelle committed 2016-07-20 16:58:58 +02:00
1 parent 08c35f5558
commit f68c1f0bde
3 files changed
+50 -9

No files matched your search

@@ -231,14 +231,21 @@ class ProjectHandler:
controller = Controller.instance()
project = controller.get_project(request.match_info["project_id"])
response.content_type = 'application/gns3project'
response.headers['CONTENT-DISPOSITION'] = 'attachment; filename="{}.gns3project"'.format(project.name)
response.enable_chunked_encoding()
# Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
response.content_length = None
response.start(request)
started = False
for data in project.export(include_images=bool(request.GET.get("include_images", "0"))):
# We need to do that now because export could failed and raise an HTTP error
# that why response start need to be the later possible
if not started:
response.content_type = 'application/gns3project'
response.headers['CONTENT-DISPOSITION'] = 'attachment; filename="{}.gns3project"'.format(project.name)
response.enable_chunked_encoding()
# Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
response.content_length = None
response.start(request)
started = True
response.write(data)
yield from response.drain()