Merge branch 'taijiang-tw-2.3'
This commit is contained in:
commit
cf54b63a85
|
@ -1,3 +1,5 @@
|
||||||
|
# TODO: Move these to ckanext-geoviews
|
||||||
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
|
@ -7,33 +9,68 @@ from ckan import plugins as p
|
||||||
log = getLogger(__name__)
|
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.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):
|
def update_config(self, config):
|
||||||
|
|
||||||
p.toolkit.add_public_directory(config, 'public')
|
p.toolkit.add_public_directory(config, 'public')
|
||||||
p.toolkit.add_template_directory(config, 'templates')
|
p.toolkit.add_template_directory(config, 'templates')
|
||||||
p.toolkit.add_resource('public', 'ckanext-spatial')
|
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):
|
def setup_template_variables(self, context, data_dict):
|
||||||
import ckanext.resourceproxy.plugin as proxy
|
import ckanext.resourceproxy.plugin as proxy
|
||||||
if self.proxy_enabled and not data_dict['resource']['on_same_domain']:
|
self.same_domain = data_dict['resource'].get('on_same_domain')
|
||||||
p.toolkit.c.resource['proxy_url'] = proxy.get_proxified_resource_url(data_dict)
|
if self.proxy_is_enabled and not self.same_domain:
|
||||||
else:
|
data_dict['resource']['original_url'] = data_dict['resource']['url']
|
||||||
p.toolkit.c.resource['proxy_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):
|
def can_preview(self, data_dict):
|
||||||
format_lower = data_dict['resource']['format'].lower()
|
format_lower = data_dict['resource']['format'].lower()
|
||||||
|
|
||||||
correct_format = format_lower in self.WMS
|
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
|
quality = 2
|
||||||
|
|
||||||
if p.toolkit.check_ckan_version('2.1'):
|
if p.toolkit.check_ckan_version('2.1'):
|
||||||
|
@ -52,10 +89,21 @@ class WMSPreview(p.SingletonPlugin):
|
||||||
def preview_template(self, context, data_dict):
|
def preview_template(self, context, data_dict):
|
||||||
return 'dataviewer/wms.html'
|
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):
|
else:
|
||||||
p.implements(p.IConfigurer, inherit=True)
|
data_dict['resource']['proxy_url'] = data_dict['resource']['url']
|
||||||
p.implements(p.IResourcePreview, inherit=True)
|
|
||||||
|
|
||||||
|
class WMSPreview(WMSView):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class GeoJSONView(DataViewBase):
|
||||||
p.implements(p.ITemplateHelpers, inherit=True)
|
p.implements(p.ITemplateHelpers, inherit=True)
|
||||||
|
|
||||||
GeoJSON = ['gjson', 'geojson']
|
GeoJSON = ['gjson', 'geojson']
|
||||||
|
@ -65,20 +113,35 @@ class GeoJSONPreview(p.SingletonPlugin):
|
||||||
template directory for the preview
|
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')
|
|
||||||
|
|
||||||
self.proxy_enabled = config.get(
|
|
||||||
'ckan.resource_proxy_enabled', False)
|
|
||||||
|
|
||||||
mimetypes.add_type('application/json', '.geojson')
|
mimetypes.add_type('application/json', '.geojson')
|
||||||
|
|
||||||
|
# IResourceView (CKAN >=2.3)
|
||||||
|
def info(self):
|
||||||
|
return {'name': 'geojson_view',
|
||||||
|
'title': 'GeoJSON',
|
||||||
|
'icon': 'map-marker',
|
||||||
|
'iframed': True,
|
||||||
|
'default_title': p.toolkit._('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):
|
def can_preview(self, data_dict):
|
||||||
format_lower = data_dict['resource']['format'].lower()
|
format_lower = data_dict['resource']['format'].lower()
|
||||||
|
|
||||||
correct_format = format_lower in self.GeoJSON
|
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
|
quality = 2
|
||||||
|
|
||||||
if p.toolkit.check_ckan_version('2.1'):
|
if p.toolkit.check_ckan_version('2.1'):
|
||||||
|
@ -94,18 +157,10 @@ class GeoJSONPreview(p.SingletonPlugin):
|
||||||
|
|
||||||
return correct_format and can_preview_from_domain
|
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):
|
def preview_template(self, context, data_dict):
|
||||||
return 'dataviewer/geojson.html'
|
return 'dataviewer/geojson.html'
|
||||||
|
|
||||||
## ITemplateHelpers
|
# ITemplateHelpers
|
||||||
|
|
||||||
def get_helpers(self):
|
def get_helpers(self):
|
||||||
from ckanext.spatial import helpers as spatial_helpers
|
from ckanext.spatial import helpers as spatial_helpers
|
||||||
|
@ -116,3 +171,6 @@ class GeoJSONPreview(p.SingletonPlugin):
|
||||||
return {
|
return {
|
||||||
'get_common_map_config_geojson' : spatial_helpers.get_common_map_config,
|
'get_common_map_config_geojson' : spatial_helpers.get_common_map_config,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GeoJSONPreview(GeoJSONView):
|
||||||
|
pass
|
||||||
|
|
|
@ -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
|
map and add a popup showing the features properties, for those resources that
|
||||||
have a format of ``geojson`` or ``gjson``.
|
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`_
|
to your ini file. This plugin also requires the `resource_proxy`_
|
||||||
plugin (Make sure you load the ``resource_proxy`` plugin before any other
|
plugin (Make sure you load the ``resource_proxy`` plugin before any other
|
||||||
from the spatial extension)::
|
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
|
WMS Preview
|
||||||
-----------
|
-----------
|
||||||
|
@ -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
|
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`_
|
ini file. This plugin also requires the `resource_proxy`_
|
||||||
plugin (Make sure you load the ``resource_proxy`` plugin before any other
|
plugin (Make sure you load the ``resource_proxy`` plugin before any other
|
||||||
from the spatial extension::
|
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
|
.. note:: Please note that the WMS previewer included in ckanext-spatial is
|
||||||
just a proof of concept and has important limitations, and is
|
just a proof of concept and has important limitations, and is
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -30,6 +30,8 @@ setup(
|
||||||
[ckan.plugins]
|
[ckan.plugins]
|
||||||
spatial_metadata=ckanext.spatial.plugin:SpatialMetadata
|
spatial_metadata=ckanext.spatial.plugin:SpatialMetadata
|
||||||
spatial_query=ckanext.spatial.plugin:SpatialQuery
|
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
|
wms_preview=ckanext.spatial.nongeos_plugin:WMSPreview
|
||||||
geojson_preview=ckanext.spatial.nongeos_plugin:GeoJSONPreview
|
geojson_preview=ckanext.spatial.nongeos_plugin:GeoJSONPreview
|
||||||
cswserver=ckanext.spatial.plugin:CatalogueServiceWeb
|
cswserver=ckanext.spatial.plugin:CatalogueServiceWeb
|
||||||
|
|
Loading…
Reference in New Issue