diff options
-rw-r--r-- | fietsboek/views/detail.py | 7 |
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 |