mirror of
https://github.com/umap-project/umap.git
synced 2025-05-04 21:51:50 +02:00
#3 - add gzip download support
This commit is contained in:
parent
42480815fa
commit
312302df33
1 changed files with 19 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue