From 312302df332b4798dcb07218a1eafba9114428a6 Mon Sep 17 00:00:00 2001 From: Vlad Stelmakh Date: Sun, 30 Apr 2023 20:12:40 +0600 Subject: [PATCH] #3 - add gzip download support --- umap/views.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/umap/views.py b/umap/views.py index 22a21061..0f7621f2 100644 --- a/umap/views.py +++ b/umap/views.py @@ -734,12 +734,26 @@ class DataLayerVersion(DataLayerView): ) class DataLayerDownloadVersion(DataLayerView): - def render_to_response(self, context, **response_kwargs): - with open(self.path, 'rb') as f: - response = HttpResponse(f, content_type='application/geo+json') - response['Content-Disposition'] = f'attachment; filename="{os.path.basename(self.path)}"' - + def render_to_response(self, context, **response_kwargs): + supported_types = { + 'geojson': 'application/geo+json', + 'gzip': 'application/gzip' + } + + ext = self.request.GET.get('ext', 'geojson') + + if ext not in supported_types: + raise ValueError('Unsupported file type: {}'.format(ext)) + + file_path = self.path + ('.gz' if ext == 'gzip' else '') + content_type = supported_types[ext] + + with open(file_path, 'rb') as f: + response = HttpResponse(f, content_type=content_type) + response['Content-Disposition'] = f'attachment; filename="{os.path.basename(file_path)}"' + return response +