Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Apr 2, 2015
2 parents efe2037 + cf54b63 commit a0bfd87
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 53 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
ckanext-spatial - Geo related plugins for CKAN
==============================================

.. image:: https://travis-ci.org/ckan/ckanext-spatial.svg?branch=master
:target: https://travis-ci.org/ckan/ckanext-spatial


This extension contains plugins that add geospatial capabilities to CKAN_,
including:
Expand Down
118 changes: 88 additions & 30 deletions ckanext/spatial/nongeos_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO: Move these to ckanext-geoviews

import mimetypes
from logging import getLogger

Expand All @@ -7,33 +9,68 @@
log = getLogger(__name__)


class WMSPreview(p.SingletonPlugin):

class DataViewBase(p.SingletonPlugin):
'''This base class is for view extensions. '''
if p.toolkit.check_ckan_version(min_version='2.3'):
p.implements(p.IResourceView, inherit=True)
else:
p.implements(p.IResourcePreview, inherit=True)
p.implements(p.IConfigurer, inherit=True)
p.implements(p.IResourcePreview, inherit=True)
p.implements(p.IConfigurable, inherit=True)

WMS = ['wms']
proxy_is_enabled = False
same_domain = False

def update_config(self, config):

p.toolkit.add_public_directory(config, 'public')
p.toolkit.add_template_directory(config, 'templates')
p.toolkit.add_resource('public', 'ckanext-spatial')

self.proxy_enabled = p.toolkit.asbool(config.get('ckan.resource_proxy_enabled', 'False'))
config['ckan.resource_proxy_enabled'] = p.plugin_loaded('resource_proxy')

def configure(self, config):
enabled = config.get('ckan.resource_proxy_enabled', False)
self.proxy_is_enabled = enabled

def setup_template_variables(self, context, data_dict):
import ckanext.resourceproxy.plugin as proxy
if self.proxy_enabled and not data_dict['resource']['on_same_domain']:
p.toolkit.c.resource['proxy_url'] = proxy.get_proxified_resource_url(data_dict)
else:
p.toolkit.c.resource['proxy_url'] = data_dict['resource']['url']
self.same_domain = data_dict['resource'].get('on_same_domain')
if self.proxy_is_enabled and not self.same_domain:
data_dict['resource']['original_url'] = data_dict['resource']['url']
data_dict['resource']['url'] = proxy.get_proxified_resource_url(data_dict)



class WMSView(DataViewBase):
WMS = ['wms']

# IResourceView (CKAN >=2.3)
def info(self):
return {'name': 'wms_view',
'title': 'WMS',
'icon': 'map-marker',
'iframed': True,
'default_title': p.toolkit._('WMS'),
}

def can_view(self, data_dict):
resource = data_dict['resource']
format_lower = resource['format'].lower()

if format_lower in self.WMS:
return self.same_domain or self.proxy_is_enabled
return False

def view_template(self, context, data_dict):
return 'dataviewer/wms.html'

# IResourcePreview (CKAN < 2.3)

def can_preview(self, data_dict):
format_lower = data_dict['resource']['format'].lower()

correct_format = format_lower in self.WMS
can_preview_from_domain = self.proxy_enabled or data_dict['resource']['on_same_domain']
can_preview_from_domain = self.proxy_is_enabled or data_dict['resource']['on_same_domain']
quality = 2

if p.toolkit.check_ckan_version('2.1'):
Expand All @@ -52,10 +89,21 @@ def can_preview(self, data_dict):
def preview_template(self, context, data_dict):
return 'dataviewer/wms.html'

def setup_template_variables(self, context, data_dict):
import ckanext.resourceproxy.plugin as proxy
self.same_domain = data_dict['resource'].get('on_same_domain')
if self.proxy_is_enabled and not self.same_domain:
data_dict['resource']['proxy_url'] = proxy.get_proxified_resource_url(data_dict)

class GeoJSONPreview(p.SingletonPlugin):
p.implements(p.IConfigurer, inherit=True)
p.implements(p.IResourcePreview, inherit=True)
else:
data_dict['resource']['proxy_url'] = data_dict['resource']['url']


class WMSPreview(WMSView):
pass


class GeoJSONView(DataViewBase):
p.implements(p.ITemplateHelpers, inherit=True)

GeoJSON = ['gjson', 'geojson']
Expand All @@ -65,20 +113,35 @@ def update_config(self, config):
template directory for the preview
'''

p.toolkit.add_public_directory(config, 'public')
p.toolkit.add_template_directory(config, 'templates')
p.toolkit.add_resource('public', 'ckanext-spatial')
mimetypes.add_type('application/json', '.geojson')

self.proxy_enabled = config.get(
'ckan.resource_proxy_enabled', False)
# IResourceView (CKAN >=2.3)
def info(self):
return {'name': 'geojson_view',
'title': 'GeoJSON',
'icon': 'map-marker',
'iframed': True,
'default_title': p.toolkit._('GeoJSON'),
}

mimetypes.add_type('application/json', '.geojson')
def can_view(self, data_dict):
resource = data_dict['resource']
format_lower = resource['format'].lower()

if format_lower in self.GeoJSON:
return self.same_domain or self.proxy_is_enabled
return False

def view_template(self, context, data_dict):
return 'dataviewer/geojson.html'

# IResourcePreview (CKAN < 2.3)

def can_preview(self, data_dict):
format_lower = data_dict['resource']['format'].lower()

correct_format = format_lower in self.GeoJSON
can_preview_from_domain = self.proxy_enabled or data_dict['resource']['on_same_domain']
can_preview_from_domain = self.proxy_is_enabled or data_dict['resource']['on_same_domain']
quality = 2

if p.toolkit.check_ckan_version('2.1'):
Expand All @@ -94,18 +157,10 @@ def can_preview(self, data_dict):

return correct_format and can_preview_from_domain

def setup_template_variables(self, context, data_dict):
import ckanext.resourceproxy.plugin as proxy
if (self.proxy_enabled
and not data_dict['resource']['on_same_domain']):
p.toolkit.c.resource['original_url'] = p.toolkit.c.resource['url']
p.toolkit.c.resource['url'] = proxy.get_proxified_resource_url(
data_dict)

def preview_template(self, context, data_dict):
return 'dataviewer/geojson.html'

## ITemplateHelpers
# ITemplateHelpers

def get_helpers(self):
from ckanext.spatial import helpers as spatial_helpers
Expand All @@ -116,3 +171,6 @@ def get_helpers(self):
return {
'get_common_map_config_geojson' : spatial_helpers.get_common_map_config,
}

class GeoJSONPreview(GeoJSONView):
pass
25 changes: 6 additions & 19 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Ubuntu 14.04 (PostgreSQL 9.3 and PostGIS 2.1)
Ubuntu 12.04 (PostgreSQL 9.1 and PostGIS 1.5)
+++++++++++++++++++++++++++++++++++++++++++++

.. note:: You can also install PostGIS 2.x on Ubuntu 12.04 using the packages
on the UbuntuGIS_ repository. Check the documentation there for details.

#. Install PostGIS::

sudo apt-get install postgresql-9.1-postgis
Expand Down Expand Up @@ -98,29 +101,13 @@ Ubuntu 12.04 (PostgreSQL 9.1 and PostGIS 1.5)
sudo apt-get install python-dev libxml2-dev libxslt1-dev libgeos-c1


.. _UbuntuGIS: https://wiki.ubuntu.com/UbuntuGIS

Install the extension
---------------------

1. Install this extension into your python environment (where CKAN is also
installed).

.. note:: Depending on the CKAN core version you are targeting you will need
to use a different branch from the extension.

For a production site, use the ``stable`` branch, unless there is a specific
branch that targets the CKAN core version that you are using.

To target the latest CKAN core release::

(pyenv) $ pip install -e "git+https://github.com/okfn/ckanext-spatial.git@stable#egg=ckanext-spatial"

To target an old release (if a release branch exists, otherwise use
``stable``)::

(pyenv) $ pip install -e "git+https://github.com/okfn/ckanext-spatial.git@release-v1.8#egg=ckanext-spatial"

To target CKAN ``master``, use the extension ``master`` branch (ie no
branch defined)::
installed)::

(pyenv) $ pip install -e "git+https://github.com/okfn/ckanext-spatial.git#egg=ckanext-spatial"

Expand Down
11 changes: 7 additions & 4 deletions doc/previews.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ The GeoJSON previewer is based on Leaflet_. It will render GeoJSON_ files on a
map and add a popup showing the features properties, for those resources that
have a format of ``geojson`` or ``gjson``.

To enable the GeoJSON previewer you need to add the ``geojson_preview`` plugin
To enable the GeoJSON previewer you need to add the ``geojson_view`` plugin
to your ini file. This plugin also requires the `resource_proxy`_
plugin (Make sure you load the ``resource_proxy`` plugin before any other
from the spatial extension)::

ckan.plugins = resource_proxy geojson_preview
ckan.plugins = resource_proxy geojson_view

.. note:: If using CKAN < 2.3, use `geojson_preview`

WMS Preview
-----------
Expand All @@ -39,12 +40,14 @@ just the main WMS service endpoint, for example:

http://vmap0.tiles.osgeo.org/wms/vmap0?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1

To enable the WMS previewer you need to add the ``wms_preview`` plugin to your
To enable the WMS previewer you need to add the ``wms_view`` plugin to your
ini file. This plugin also requires the `resource_proxy`_
plugin (Make sure you load the ``resource_proxy`` plugin before any other
from the spatial extension::

ckan.plugins = resource_proxy wms_preview
ckan.plugins = resource_proxy wms_view

.. note:: If using CKAN < 2.3, use `geojson_preview`

.. note:: Please note that the WMS previewer included in ckanext-spatial is
just a proof of concept and has important limitations, and is
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
[ckan.plugins]
spatial_metadata=ckanext.spatial.plugin:SpatialMetadata
spatial_query=ckanext.spatial.plugin:SpatialQuery
wms_view=ckanext.spatial.nongeos_plugin:WMSView
geojson_view=ckanext.spatial.nongeos_plugin:GeoJSONView
wms_preview=ckanext.spatial.nongeos_plugin:WMSPreview
geojson_preview=ckanext.spatial.nongeos_plugin:GeoJSONPreview
cswserver=ckanext.spatial.plugin:CatalogueServiceWeb
Expand Down

0 comments on commit a0bfd87

Please sign in to comment.