aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-08-02 22:00:26 +0200
committerDaniel Schadt <kingdread@gmx.de>2023-08-02 22:07:43 +0200
commitd2afc66d282aef7484306738b302c8a87814364f (patch)
tree4f8036c6b5c8c5d5b9b633b8bc537c87ae6ba454
parentf3e2a465df442ce22929edf0aaf9c1dde2bb63c7 (diff)
downloadfietsboek-d2afc66d282aef7484306738b302c8a87814364f.tar.gz
fietsboek-d2afc66d282aef7484306738b302c8a87814364f.tar.bz2
fietsboek-d2afc66d282aef7484306738b302c8a87814364f.zip
use content-disposition for GPX download
Makes for nicer download filenames!
-rw-r--r--fietsboek/views/detail.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/fietsboek/views/detail.py b/fietsboek/views/detail.py
index ec66922..8e296b7 100644
--- a/fietsboek/views/detail.py
+++ b/fietsboek/views/detail.py
@@ -15,7 +15,7 @@ from pyramid.view import view_config
from sqlalchemy import select
from .. import models, util
-from ..models.track import TrackWithMetadata
+from ..models.track import Track, TrackWithMetadata
LOGGER = logging.getLogger(__name__)
@@ -91,12 +91,14 @@ def gpx(request):
:return: The HTTP response.
:rtype: pyramid.response.Response
"""
- track = request.context
+ track: Track = request.context
try:
manager = request.data_manager.open(track.id)
except FileNotFoundError:
LOGGER.error("Track exists in database, but not on disk: %d", track.id)
return HTTPInternalServerError()
+ wanted_filename = f"{track.id} - {util.secure_filename(track.title)}.gpx"
+ content_disposition = f'attachment; filename="{wanted_filename}"'
# We can be nice to the client if they support it, and deliver the gzipped
# data straight. This saves decompression time on the server and saves a
# lot of bandwidth.
@@ -122,6 +124,7 @@ def gpx(request):
else:
return HTTPNotAcceptable("No data with acceptable encoding found")
response.md5_etag()
+ response.content_disposition = content_disposition
return response