From d2afc66d282aef7484306738b302c8a87814364f Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 2 Aug 2023 22:00:26 +0200 Subject: use content-disposition for GPX download Makes for nicer download filenames! --- fietsboek/views/detail.py | 7 +++++-- 1 file 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 -- cgit v1.2.3