Skip to content

Commit

Permalink
[worldmap-client] Makes Google StreetView optional. Bump django-geoex…
Browse files Browse the repository at this point in the history
…plorer-worldmap 4.0.61. Remove some unused code
  • Loading branch information
capooti committed Dec 6, 2018
1 parent 388fc11 commit 434d68d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 72 deletions.
2 changes: 2 additions & 0 deletions geonode/client/templates/worldmap/maps/map_worldmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@
toggleGroup: 'featureGroup',
actionTarget: {target: "paneltbar", index: 6}
},
{% if USE_GOOGLE_STREET_VIEW %}
{
ptype: "gxp_streetviewtool",
actionTarget: {target: "paneltbar", index: 7},
toggleGroup: 'featureGroup'
},
{% endif %}
{
ptype: "gxp_measure",
toggleGroup: 'featureGroup',
Expand Down
2 changes: 2 additions & 0 deletions geonode/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def resource_urls(request):
'worldmap,geonames,nominatim'
)

defaults['USE_GOOGLE_STREET_VIEW'] = settings.USE_GOOGLE_STREET_VIEW

defaults['GOOGLE_API_KEY'] = settings.GOOGLE_API_KEY

defaults['GOOGLE_MAPS_API_KEY'] = settings.GOOGLE_MAPS_API_KEY
Expand Down
72 changes: 1 addition & 71 deletions geonode/contrib/worldmap/wm_extra/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
import math
import re
import urlparse
from httplib import HTTPConnection, HTTPSConnection
from urlparse import urlsplit

from guardian.shortcuts import get_perms

from django.conf import settings
from django.db.models import F
from django.utils.http import is_safe_url
from django.http.request import validate_host
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ObjectDoesNotExist
from django.core.serializers.json import DjangoJSONEncoder
Expand Down Expand Up @@ -45,73 +41,6 @@
ows_sub = re.compile(r"[&\?]+SERVICE=WMS|[&\?]+REQUEST=GetCapabilities", re.IGNORECASE)


@csrf_exempt
def proxy(request):
PROXY_ALLOWED_HOSTS = getattr(settings, 'PROXY_ALLOWED_HOSTS', ())

host = None

if 'geonode.geoserver' in settings.INSTALLED_APPS:
from geonode.geoserver.helpers import ogc_server_settings
hostname = (ogc_server_settings.hostname,) if ogc_server_settings else ()
PROXY_ALLOWED_HOSTS += hostname
host = ogc_server_settings.netloc

if 'url' not in request.GET:
return HttpResponse("The proxy service requires a URL-encoded URL as a parameter.",
status=400,
content_type="text/plain"
)

raw_url = request.GET['url']
url = urlsplit(raw_url)
locator = str(url.path)
if url.query != "":
locator += '?' + url.query
if url.fragment != "":
locator += '#' + url.fragment

if not settings.DEBUG:
if not validate_host(url.hostname, PROXY_ALLOWED_HOSTS):
return HttpResponse("DEBUG is set to False but the host of the path provided to the proxy service"
" is not in the PROXY_ALLOWED_HOSTS setting.",
status=403,
content_type="text/plain"
)
headers = {}

if settings.SESSION_COOKIE_NAME in request.COOKIES and is_safe_url(url=raw_url, host=host):
headers["Cookie"] = request.META["HTTP_COOKIE"]

if request.method in ("POST", "PUT") and "CONTENT_TYPE" in request.META:
headers["Content-Type"] = request.META["CONTENT_TYPE"]

if url.scheme == 'https':
conn = HTTPSConnection(url.hostname, url.port)
else:
conn = HTTPConnection(url.hostname, url.port)
conn.request(request.method, locator, request.body, headers)

result = conn.getresponse()

# If we get a redirect, let's add a useful message.
if result.status in (301, 302, 303, 307):
response = HttpResponse(('This proxy does not support redirects. The server in "%s" '
'asked for a redirect to "%s"' % (url, result.getheader('Location'))),
status=result.status,
content_type=result.getheader("Content-Type", "text/plain")
)

response['Location'] = result.getheader('Location')
else:
response = HttpResponse(
result.read(),
status=result.status,
content_type=result.getheader("Content-Type", "text/plain"))

return response


def ajax_snapshot_history(request, mapid):
map_obj = Map.objects.get(pk=mapid)
history = [snapshot.json() for snapshot in map_obj.snapshots]
Expand Down Expand Up @@ -394,6 +323,7 @@ def new_map_wm(request, template='wm_extra/maps/map_new.html'):
return render(request, template, context_dict)


@csrf_exempt
def new_map_json_wm(request):
if request.method == 'GET':
config = new_map_config(request)
Expand Down
1 change: 1 addition & 0 deletions geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,7 @@
organized spatially and temporally.</p>
"""
# these are optionals
USE_GOOGLE_STREET_VIEW = strtobool(os.getenv('USE_GOOGLE_STREET_VIEW', 'False'))
GOOGLE_MAPS_API_KEY = os.getenv('GOOGLE_MAPS_API_KEY', 'your-key-here')
USE_HYPERMAP = strtobool(os.getenv('USE_HYPERMAP', 'False'))
HYPERMAP_REGISTRY_URL = os.getenv('HYPERMAP_REGISTRY_URL', 'http://localhost:8001')
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pycountry
# required by worldmap
datautil==0.4
dicttoxml==1.7.4
django-geoexplorer-worldmap==4.0.60
django-geoexplorer-worldmap==4.0.61
geopy==1.14.0
vectorformats==0.1

Expand Down

0 comments on commit 434d68d

Please sign in to comment.