From cb1243ee778aa1169b67e44a334186e23fc503df Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 26 Nov 2013 17:03:33 +0100 Subject: [PATCH] provide a config option to specify a googlemap API key if needed --- myslice/config.py | 5 +++++ plugins/googlemap/__init__.py | 17 ++++++++++++----- portal/resourceview.py | 19 +++++++++++-------- portal/sliceview.py | 1 + 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/myslice/config.py b/myslice/config.py index 04f4aaf8..908b6512 100644 --- a/myslice/config.py +++ b/myslice/config.py @@ -33,6 +33,8 @@ class Config(object): parser.set ('manifold', 'url', Config.default_manifold_url) parser.set ('manifold', 'admin_user', Config.default_manifold_admin_user) parser.set ('manifold', 'admin_password', Config.default_manifold_admin_password) + parser.add_section('googlemap') + parser.set ('googlemap','api_key', None) parser.read (os.path.join(ROOT,'myslice/myslice.ini')) self.config_parser=parser @@ -43,6 +45,9 @@ class Config(object): return (self.config_parser.get('manifold','admin_user'), self.config_parser.get('manifold','admin_password')) + def googlemap_api_key (self): + return self.config_parser.get('googlemap','api_key') + # exporting these details to js def manifold_js_export (self): return "var MANIFOLD_URL = '%s';\n"%self.manifold_url(); diff --git a/plugins/googlemap/__init__.py b/plugins/googlemap/__init__.py index bce84f54..8ceaec63 100644 --- a/plugins/googlemap/__init__.py +++ b/plugins/googlemap/__init__.py @@ -2,14 +2,17 @@ from unfold.plugin import Plugin class GoogleMap (Plugin): - # set checkboxes if a final column with checkboxes is desired - # pass columns as the initial set of columns - # if None then this is taken from the query's fields + # expcted input are + # query : query about the slice + # query_all : query about all resources + # googlemap_key : mandatory googlemap API v3 key # latitude,longitude, zoom : the starting point - def __init__ (self, query, query_all = None, latitude=43., longitude=7., zoom=4, **settings): + # apparently at some point there has been support for a boolean 'checkboxes' input arg but seems dropped + def __init__ (self, query, query_all, googlemap_api_key=None, latitude=43., longitude=7., zoom=4, **settings): Plugin.__init__ (self, **settings) self.query=query self.query_all = query_all + self.googlemap_api_key=googlemap_api_key self.query_all_uuid = query_all.query_uuid if query_all else None self.latitude=latitude self.longitude=longitude @@ -23,8 +26,12 @@ class GoogleMap (Plugin): return env def requirements (self): + googlemap_api_url = "https://maps.googleapis.com/maps/api/js?" + if self.googlemap_api_key: googlemap_api_url+="key=%s&"%self.googlemap_api_key + googlemap_api_url += "sensor=false" reqs = { - 'js_files' : [ "https://maps.googleapis.com/maps/api/js?sensor=false", + # let users configure their googlemap API key in production deployements + 'js_files' : [ googlemap_api_url, "/js/googlemap.js", "/js/markerclusterer.js", "js/manifold.js", "js/manifold-query.js", diff --git a/portal/resourceview.py b/portal/resourceview.py index f0f856ae..155eff3f 100644 --- a/portal/resourceview.py +++ b/portal/resourceview.py @@ -1,13 +1,15 @@ -from manifold.core.query import Query -from unfold.page import Page +from manifold.core.query import Query +from unfold.page import Page -from unfold.loginrequired import FreeAccessView -from ui.topmenu import topmenu_items, the_user +from unfold.loginrequired import FreeAccessView +from ui.topmenu import topmenu_items, the_user -from plugins.googlemap import GoogleMap -from plugins.querytable import QueryTable -from plugins.lists.simplelist import SimpleList -from plugins.slicestat import SliceStat +from plugins.googlemap import GoogleMap +from plugins.querytable import QueryTable +from plugins.lists.simplelist import SimpleList +from plugins.slicestat import SliceStat + +from myslice.config import Config # View for 1 platform and its details class ResourceView(FreeAccessView): @@ -52,6 +54,7 @@ class ResourceView(FreeAccessView): togglable = True, query = resource_query, query_all = resource_query, + googlemap_api_key = Config().googlemap_api_key(), checkboxes = False, # center on Paris #latitude = 49., diff --git a/portal/sliceview.py b/portal/sliceview.py index 38223210..753c92a2 100644 --- a/portal/sliceview.py +++ b/portal/sliceview.py @@ -156,6 +156,7 @@ class SliceView (LoginRequiredAutoLogoutView): togglable = False, query = sq_resource, query_all = query_resource_all, + googlemap_api_key = Config().googlemap_api_key(), checkboxes = True, # center on Paris latitude = 49., -- 2.43.0