[ckan-changes] commit/ckanext-spatial: amercader: Separate non-GEOS/PostGIS plugins to avoid needing to install them if not needed

Bitbucket commits-noreply at bitbucket.org
Fri Oct 28 12:03:45 UTC 2011


1 new commit in ckanext-spatial:


https://bitbucket.org/okfn/ckanext-spatial/changeset/effd4abb74d4/
changeset:   effd4abb74d4
user:        amercader
date:        2011-10-28 14:03:31
summary:     Separate non-GEOS/PostGIS plugins to avoid needing to install them if not needed

I.e for the WMS preview plugin. Also add tests for the WMS preview plugin and
use dataset instead of package on the UI.
affected #:  6 files

diff -r 0c12873ec4413e9258a04ba0702f69fa9773ce69 -r effd4abb74d4478eecab2b37653ee780059c7788 ckanext/spatial/controllers/view.py
--- a/ckanext/spatial/controllers/view.py
+++ b/ckanext/spatial/controllers/view.py
@@ -14,14 +14,14 @@
         #check if package exists
         c.pkg = Package.get(id)
         if c.pkg is None:
-            abort(404, 'Package not found')
+            abort(404, 'Dataset not found')
 
         for res in c.pkg.resources:
             if res.format == "WMS":
                 c.wms_url = res.url if not '?' in res.url else res.url.split('?')[0]
                 break
         if not c.wms_url:
-            abort(400, 'This package does not have a WMS resource')
+            abort(400, 'This dataset does not have a WMS resource')
 
         return render('ckanext/spatial/wms_preview.html')
 


diff -r 0c12873ec4413e9258a04ba0702f69fa9773ce69 -r effd4abb74d4478eecab2b37653ee780059c7788 ckanext/spatial/html.py
--- a/ckanext/spatial/html.py
+++ b/ckanext/spatial/html.py
@@ -1,6 +1,6 @@
 MAP_VIEW="""
 <div class="mapview">
-    <a href="/package/%(name)s/map">View available WMS layers »</a>
+    <a href="/dataset/%(name)s/map">View available WMS layers »</a></div>
 """
 


diff -r 0c12873ec4413e9258a04ba0702f69fa9773ce69 -r effd4abb74d4478eecab2b37653ee780059c7788 ckanext/spatial/nongeos_plugin.py
--- /dev/null
+++ b/ckanext/spatial/nongeos_plugin.py
@@ -0,0 +1,72 @@
+import os
+from logging import getLogger
+from pylons.i18n import _
+from genshi.input import HTML
+from genshi.filters import Transformer
+
+import ckan.lib.helpers as h
+
+from ckan.lib.helpers import json
+
+from ckan.plugins import implements, SingletonPlugin
+from ckan.plugins import IRoutes, IConfigurer
+from ckan.plugins import IGenshiStreamFilter
+
+import html
+
+
+log = getLogger(__name__)
+
+class WMSPreview(SingletonPlugin):
+
+    implements(IGenshiStreamFilter)
+    implements(IRoutes, inherit=True)
+    implements(IConfigurer, inherit=True)
+
+    def filter(self, stream):
+        from pylons import request, tmpl_context as c
+        routes = request.environ.get('pylons.routes_dict')
+
+        if routes.get('controller') == 'package' and \
+            routes.get('action') == 'read' and c.pkg.id:
+
+            for res in c.pkg.resources:
+                if res.format == "WMS":
+                    data = {'name': c.pkg.name}
+                    stream = stream | Transformer('body//div[@class="resources subsection"]')\
+                        .append(HTML(html.MAP_VIEW % data))
+
+                    break
+
+
+
+        return stream
+
+    def before_map(self, map):
+
+        map.redirect('/package/{id}/map','/dataset/{id}/map')
+        map.connect('map_view', '/dataset/:id/map',
+            controller='ckanext.spatial.controllers.view:ViewController',
+            action='wms_preview')
+
+        map.connect('proxy', '/proxy',
+            controller='ckanext.spatial.controllers.view:ViewController',
+            action='proxy')
+
+        return map
+
+    def update_config(self, config):
+        here = os.path.dirname(__file__)
+
+        template_dir = os.path.join(here, 'templates')
+        public_dir = os.path.join(here, 'public')
+
+        if config.get('extra_template_paths'):
+            config['extra_template_paths'] += ','+template_dir
+        else:
+            config['extra_template_paths'] = template_dir
+        if config.get('extra_public_paths'):
+            config['extra_public_paths'] += ','+public_dir
+        else:
+            config['extra_public_paths'] = public_dir
+


diff -r 0c12873ec4413e9258a04ba0702f69fa9773ce69 -r effd4abb74d4478eecab2b37653ee780059c7788 ckanext/spatial/plugin.py
--- a/ckanext/spatial/plugin.py
+++ b/ckanext/spatial/plugin.py
@@ -10,7 +10,7 @@
 
 from ckan.plugins import implements, SingletonPlugin
 from ckan.plugins import IRoutes, IConfigurer
-from ckan.plugins import IConfigurable, IGenshiStreamFilter
+from ckan.plugins import IGenshiStreamFilter
 from ckan.plugins import IPackageController
 
 from ckan.logic import ValidationError
@@ -121,57 +121,3 @@
         else:
             config['extra_public_paths'] = public_dir
 
-
-
-class WMSPreview(SingletonPlugin):
-
-    implements(IGenshiStreamFilter)
-    implements(IRoutes, inherit=True)
-    implements(IConfigurer, inherit=True)
-
-    def filter(self, stream):
-        from pylons import request, tmpl_context as c
-        routes = request.environ.get('pylons.routes_dict')
-
-        if routes.get('controller') == 'package' and \
-            routes.get('action') == 'read' and c.pkg.id:
-
-            for res in c.pkg.resources:
-                if res.format == "WMS":
-                    data = {'name': c.pkg.name}
-                    stream = stream | Transformer('body//div[@class="resources subsection"]')\
-                        .append(HTML(html.MAP_VIEW % data))
-
-                    break
-
-
-
-        return stream
-
-    def before_map(self, map):
-
-        map.connect('map_view', '/package/:id/map',
-            controller='ckanext.spatial.controllers.view:ViewController',
-            action='wms_preview')
-
-        map.connect('proxy', '/proxy',
-            controller='ckanext.spatial.controllers.view:ViewController',
-            action='proxy')
-
-        return map
-
-    def update_config(self, config):
-        here = os.path.dirname(__file__)
-
-        template_dir = os.path.join(here, 'templates')
-        public_dir = os.path.join(here, 'public')
-
-        if config.get('extra_template_paths'):
-            config['extra_template_paths'] += ','+template_dir
-        else:
-            config['extra_template_paths'] = template_dir
-        if config.get('extra_public_paths'):
-            config['extra_public_paths'] += ','+public_dir
-        else:
-            config['extra_public_paths'] = public_dir
-


diff -r 0c12873ec4413e9258a04ba0702f69fa9773ce69 -r effd4abb74d4478eecab2b37653ee780059c7788 ckanext/spatial/tests/test_wms_preview.py
--- /dev/null
+++ b/ckanext/spatial/tests/test_wms_preview.py
@@ -0,0 +1,62 @@
+import logging
+from pprint import pprint
+from ckan import model
+from ckan.model import Package, Resource
+from ckan.lib.helpers import url_for,json
+
+from ckan.tests import CreateTestData
+from ckan.tests.functional.base import FunctionalTestCase
+
+from ckanext.spatial.tests import SpatialTestBase
+
+log = logging.getLogger(__name__)
+
+
+class TestWMSPreview(FunctionalTestCase,SpatialTestBase):
+    def setup(self):
+        CreateTestData.create()
+
+    def teardown(self):
+        CreateTestData.delete()
+
+    def test_link_and_map_shown(self):
+
+        name = u'annakarenina'
+        
+        wms_url = 'http://maps.bgs.ac.uk/ArcGIS/services/BGS_Detailed_Geology/MapServer/WMSServer?'
+        rev = model.repo.new_revision()
+        pkg = Package.get(name)
+        pr = Resource(url=wms_url,format='WMS')
+        pkg.resources.append(pr)
+        pkg.save()
+        model.repo.commit_and_remove()
+        # Load the dataset page and check if link appears
+        offset = url_for(controller='package', action='read',id=name)
+        res = self.app.get(offset)
+
+        assert 'View available WMS layers' in res, res
+
+        # Load the dataset map preview page and check if libraries are loaded
+        offset = '/dataset/%s/map' % name 
+        res = self.app.get(offset)
+        assert '<script type="text/javascript" src="/ckanext/spatial/js/wms_preview.js"></script>' in res, res
+        assert 'CKAN.WMSPreview.setup("%s");' % wms_url.split('?')[0] in res
+ 
+    def test_link_and_map_not_shown(self):
+
+        name = 'annakarenina'
+
+        offset = url_for(controller='package', action='read',id=name)
+
+        # Load the dataset page and check that link does not appear
+        offset = url_for(controller='package', action='read',id=name)
+        res = self.app.get(offset)
+
+        assert not 'View available WMS layers' in res, res
+
+        # Load the dataset map preview page and check that libraries are not loaded
+        offset = '/dataset/%s/map' % name 
+        res = self.app.get(offset, status=400)
+        assert '400 Bad Request' in res, res
+        assert 'This dataset does not have a WMS resource' in res
+        assert not '<script type="text/javascript" src="/ckanext/spatial/js/wms_preview.js"></script>' in res


diff -r 0c12873ec4413e9258a04ba0702f69fa9773ce69 -r effd4abb74d4478eecab2b37653ee780059c7788 setup.py
--- a/setup.py
+++ b/setup.py
@@ -26,7 +26,7 @@
 	"""
     [ckan.plugins]
 	# Add plugins here, eg
-	wms_preview=ckanext.spatial.plugin:WMSPreview
+	wms_preview=ckanext.spatial.nongeos_plugin:WMSPreview
  	spatial_query=ckanext.spatial.plugin:SpatialQuery
  	dataset_extent_map=ckanext.spatial.plugin:DatasetExtentMap
     [paste.paster_command]

Repository URL: https://bitbucket.org/okfn/ckanext-spatial/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list