Split plugins
This commit is contained in:
parent
150d9688a6
commit
75a37f8ce4
|
@ -9,6 +9,14 @@ from ckan import plugins as p
|
|||
|
||||
from ckan.lib.helpers import json
|
||||
|
||||
if p.toolkit.check_ckan_version(min_version="2.9"):
|
||||
from ckanext.spatial.plugin.flask_plugin import (
|
||||
SpatialQueryMixin, HarvestMetadataApiMixin
|
||||
)
|
||||
else:
|
||||
from ckanext.spatial.plugin.pylons_plugin import (
|
||||
SpatialQueryMixin, HarvestMetadataApiMixin
|
||||
)
|
||||
|
||||
def check_geoalchemy_requirement():
|
||||
'''Checks if a suitable geoalchemy version installed
|
||||
|
@ -77,9 +85,9 @@ class SpatialMetadata(p.SingletonPlugin):
|
|||
''' Set up the resource library, public directory and
|
||||
template directory for all the spatial extensions
|
||||
'''
|
||||
p.toolkit.add_public_directory(config, 'public')
|
||||
p.toolkit.add_template_directory(config, 'templates')
|
||||
p.toolkit.add_resource('public', 'ckanext-spatial')
|
||||
p.toolkit.add_public_directory(config, '../public')
|
||||
p.toolkit.add_template_directory(config, '../templates')
|
||||
p.toolkit.add_resource('../public', 'ckanext-spatial')
|
||||
|
||||
# Add media types for common extensions not included in the mimetypes
|
||||
# module
|
||||
|
@ -150,9 +158,8 @@ class SpatialMetadata(p.SingletonPlugin):
|
|||
'get_common_map_config' : spatial_helpers.get_common_map_config,
|
||||
}
|
||||
|
||||
class SpatialQuery(p.SingletonPlugin):
|
||||
class SpatialQuery(SpatialQueryMixin, p.SingletonPlugin):
|
||||
|
||||
p.implements(p.IRoutes, inherit=True)
|
||||
p.implements(p.IPackageController, inherit=True)
|
||||
p.implements(p.IConfigurable, inherit=True)
|
||||
|
||||
|
@ -166,13 +173,6 @@ class SpatialQuery(p.SingletonPlugin):
|
|||
'Please upgrade CKAN or select the \'postgis\' backend.'
|
||||
raise p.toolkit.CkanVersionException(msg)
|
||||
|
||||
def before_map(self, map):
|
||||
|
||||
map.connect('api_spatial_query', '/api/2/search/{register:dataset|package}/geo',
|
||||
controller='ckanext.spatial.controllers.api:ApiController',
|
||||
action='spatial_query')
|
||||
return map
|
||||
|
||||
def before_index(self, pkg_dict):
|
||||
import shapely
|
||||
import shapely.geometry
|
||||
|
@ -390,7 +390,7 @@ class SpatialQuery(p.SingletonPlugin):
|
|||
search_results['results'] = pkgs
|
||||
return search_results
|
||||
|
||||
class HarvestMetadataApi(p.SingletonPlugin):
|
||||
class HarvestMetadataApi(HarvestMetadataApiMixin, p.SingletonPlugin):
|
||||
'''
|
||||
Harvest Metadata API
|
||||
(previously called "InspireApi")
|
||||
|
@ -398,31 +398,4 @@ class HarvestMetadataApi(p.SingletonPlugin):
|
|||
A way for a user to view the harvested metadata XML, either as a raw file or
|
||||
styled to view in a web browser.
|
||||
'''
|
||||
p.implements(p.IRoutes)
|
||||
|
||||
def before_map(self, route_map):
|
||||
controller = "ckanext.spatial.controllers.api:HarvestMetadataApiController"
|
||||
|
||||
# Showing the harvest object content is an action of the default
|
||||
# harvest plugin, so just redirect there
|
||||
route_map.redirect('/api/2/rest/harvestobject/{id:.*}/xml',
|
||||
'/harvest/object/{id}',
|
||||
_redirect_code='301 Moved Permanently')
|
||||
|
||||
route_map.connect('/harvest/object/{id}/original', controller=controller,
|
||||
action='display_xml_original')
|
||||
|
||||
route_map.connect('/harvest/object/{id}/html', controller=controller,
|
||||
action='display_html')
|
||||
route_map.connect('/harvest/object/{id}/html/original', controller=controller,
|
||||
action='display_html_original')
|
||||
|
||||
# Redirect old URL to a nicer and unversioned one
|
||||
route_map.redirect('/api/2/rest/harvestobject/:id/html',
|
||||
'/harvest/object/{id}/html',
|
||||
_redirect_code='301 Moved Permanently')
|
||||
|
||||
return route_map
|
||||
|
||||
def after_map(self, route_map):
|
||||
return route_map
|
||||
pass
|
|
@ -0,0 +1,41 @@
|
|||
import ckan.plugins as p
|
||||
|
||||
|
||||
|
||||
class SpatialQueryMixin(p.SingletonPlugin):
|
||||
p.implements(p.IRoutes, inherit=True)
|
||||
|
||||
# IRoutes
|
||||
def before_map(self, map):
|
||||
|
||||
map.connect('api_spatial_query', '/api/2/search/{register:dataset|package}/geo',
|
||||
controller='ckanext.spatial.controllers.api:ApiController',
|
||||
action='spatial_query')
|
||||
return map
|
||||
|
||||
class HarvestMetadataApiMixin(p.SingletonPlugin):
|
||||
p.implements(p.IRoutes, inherit=True)
|
||||
|
||||
def before_map(self, route_map):
|
||||
controller = "ckanext.spatial.controllers.api:HarvestMetadataApiController"
|
||||
|
||||
# Showing the harvest object content is an action of the default
|
||||
# harvest plugin, so just redirect there
|
||||
route_map.redirect('/api/2/rest/harvestobject/{id:.*}/xml',
|
||||
'/harvest/object/{id}',
|
||||
_redirect_code='301 Moved Permanently')
|
||||
|
||||
route_map.connect('/harvest/object/{id}/original', controller=controller,
|
||||
action='display_xml_original')
|
||||
|
||||
route_map.connect('/harvest/object/{id}/html', controller=controller,
|
||||
action='display_html')
|
||||
route_map.connect('/harvest/object/{id}/html/original', controller=controller,
|
||||
action='display_html_original')
|
||||
|
||||
# Redirect old URL to a nicer and unversioned one
|
||||
route_map.redirect('/api/2/rest/harvestobject/:id/html',
|
||||
'/harvest/object/{id}/html',
|
||||
_redirect_code='301 Moved Permanently')
|
||||
|
||||
return route_map
|
|
@ -0,0 +1,41 @@
|
|||
import ckan.plugins as p
|
||||
|
||||
|
||||
|
||||
class SpatialQueryMixin(p.SingletonPlugin):
|
||||
p.implements(p.IRoutes, inherit=True)
|
||||
|
||||
# IRoutes
|
||||
def before_map(self, map):
|
||||
|
||||
map.connect('api_spatial_query', '/api/2/search/{register:dataset|package}/geo',
|
||||
controller='ckanext.spatial.controllers.api:ApiController',
|
||||
action='spatial_query')
|
||||
return map
|
||||
|
||||
class HarvestMetadataApiMixin(p.SingletonPlugin):
|
||||
p.implements(p.IRoutes, inherit=True)
|
||||
|
||||
def before_map(self, route_map):
|
||||
controller = "ckanext.spatial.controllers.api:HarvestMetadataApiController"
|
||||
|
||||
# Showing the harvest object content is an action of the default
|
||||
# harvest plugin, so just redirect there
|
||||
route_map.redirect('/api/2/rest/harvestobject/{id:.*}/xml',
|
||||
'/harvest/object/{id}',
|
||||
_redirect_code='301 Moved Permanently')
|
||||
|
||||
route_map.connect('/harvest/object/{id}/original', controller=controller,
|
||||
action='display_xml_original')
|
||||
|
||||
route_map.connect('/harvest/object/{id}/html', controller=controller,
|
||||
action='display_html')
|
||||
route_map.connect('/harvest/object/{id}/html/original', controller=controller,
|
||||
action='display_html_original')
|
||||
|
||||
# Redirect old URL to a nicer and unversioned one
|
||||
route_map.redirect('/api/2/rest/harvestobject/:id/html',
|
||||
'/harvest/object/{id}/html',
|
||||
_redirect_code='301 Moved Permanently')
|
||||
|
||||
return route_map
|
|
@ -6,3 +6,4 @@ lxml>=2.3
|
|||
argparse
|
||||
pyparsing>=2.1.10
|
||||
requests>=1.1.0
|
||||
future>=0.18.2
|
||||
|
|
Loading…
Reference in New Issue