Skip to content

Commit

Permalink
removes space and a few other characters from the file name
Browse files Browse the repository at this point in the history
  • Loading branch information
boney-bun committed Aug 29, 2018
1 parent ff7121b commit 673c920
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion geonode/maps/qgis_server_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import requests
import math
import logging
import re

from django.conf import settings
from django.views.generic import CreateView, DetailView, UpdateView
Expand Down Expand Up @@ -569,8 +570,10 @@ def perm_filter(layer):
fwd_request.content,
content_type="application/x-qgis-layer-definition",
status=fwd_request.status_code)
# removes dash, dot, brackets, and space from the name
title = re.sub('[()-. ]', '', map_obj.title)
response['Content-Disposition'] = 'attachment; filename=%s.qlr' \
% map_obj.title
% title

return response

Expand Down
11 changes: 8 additions & 3 deletions geonode/qgis_server/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ def download_zip(request, layername):
# Folder name in ZIP archive which contains the above files
# E.g [thearchive.zip]/somefiles/file2.txt
zip_subdir = layer.name
# removes dash, dot, brackets, and space from the name
zip_subdir = re.sub('[()-. ]', '', zip_subdir)
zip_filename = "%s.zip" % zip_subdir

# Open StringIO to grab in-memory ZIP contents
s = StringIO.StringIO()

Expand Down Expand Up @@ -129,6 +130,8 @@ def download_qgs(request, layername):
layer_title = layer.title
else:
layer_title = layer.name
# removes dash, dot, brackets, and space from the name
layer_title = re.sub('[()-. ]', '', layer_title)

response = HttpResponse(
result.content, content_type="application/x-qgis-project",
Expand All @@ -152,7 +155,8 @@ def download_map(request, mapid):
# Folder name in ZIP archive which contains the above files
# E.g [thearchive.zip]/somefiles/file2.txt
zip_subdir = [ml.layer_title for ml in map_layers if ml.local][0]
zip_subdir = re.sub('[-. ]', '', zip_subdir)
# removes dash, dot, brackets, and space from the name
zip_subdir = re.sub('[()-. ]', '', zip_subdir)
# Using map name for the zip file
zip_filename = "%s.zip" % zip_subdir

Expand Down Expand Up @@ -902,7 +906,8 @@ def download_qlr(request, layername):
layer_title = layer.title
else:
layer_title = layer.name

# removes dash, dot, brackets, and space from the name
layer_title = re.sub('[()-. ]', '', layer_title)
result = requests.get(url)
response = HttpResponse(
result.content,
Expand Down

0 comments on commit 673c920

Please sign in to comment.