diff --git a/ckanext/odsh/controller.py b/ckanext/odsh/controller.py index 119d758250fce6182f9991efe6a7280b3a3a0654..34b7eeeb94a532f25f6d5eac69257318fa00449f 100644 --- a/ckanext/odsh/controller.py +++ b/ckanext/odsh/controller.py @@ -13,6 +13,8 @@ import matomo import ckan.logic as logic from ckan.common import c, request, config import hashlib +import ckan.plugins.toolkit as toolkit +from ckanext.dcat.controllers import DCATController abort = base.abort log = logging.getLogger(__name__) @@ -64,7 +66,7 @@ class OdshUserController(UserController): class OdshPackageController(PackageController): pass -class MamotoApiController(ApiController): +class OdshApiController(ApiController): def action(self, logic_function, ver=None): try: function = logic.get_action(logic_function) @@ -88,6 +90,11 @@ class MamotoApiController(ApiController): log.error(e) return ApiController.action(self, logic_function, ver) + +class OdshDCATController(DCATController): + def read_catalog(self, _format): + matomo.create_matomo_request() + return DCATController.read_catalog(self,_format) class OdshFeedController(FeedController): def custom(self): @@ -145,4 +152,4 @@ class OdshFeedController(FeedController): feed_link=alternate_url, feed_guid=_create_atom_id(atom_url), feed_url=feed_url, - navigation_urls=navigation_urls) \ No newline at end of file + navigation_urls=navigation_urls) diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index 8214308f6ad3034736c807c029cf9b3574302118..0e511035c0e9f16253678cad0c79386e6a8e1dbc 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -61,13 +61,27 @@ def odsh_group_id_selected(selected, group_id): return False +def remove_route(map,routename): + route = None + for i,r in enumerate(map.matchlist): + + if r.name == routename: + route = r + break + if route is not None: + map.matchlist.remove(route) + for key in map.maxkeys: + if key == route.maxkeys: + map.maxkeys.pop(key) + map._routenames.pop(route.name) + break + class OdshIcapPlugin(plugins.SingletonPlugin): plugins.implements(plugins.IUploader, inherit=True) def get_resource_uploader(self, data_dict): return ODSHResourceUpload(data_dict) - class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm): plugins.implements(plugins.IConfigurer) plugins.implements(plugins.ITemplateHelpers) @@ -128,9 +142,21 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm map.redirect('/dataset/{id}/resource/{resource_id}', '/dataset/{id}') + if p.toolkit.asbool(config.get('ckanext.dcat.enable_rdf_endpoints', True)): + remove_route(map, 'dcat_catalog') + map.connect('dcat_catalog', + config.get('ckanext.dcat.catalog_endpoint', '/catalog.{_format}'), + controller='ckanext.odsh.controller:OdshDCATController', action='read_catalog', + requirements={'_format': 'xml|rdf|n3|ttl|jsonld'}) + + # with SubMapper(map, controller='ckanext.odsh.controller:OdshApiController') as m: + # m.connect('/catalog2', action='read_catalog') + + + # /api ver 3 or none with matomo GET_POST = dict(method=['GET', 'POST']) - with SubMapper(map, controller='ckanext.odsh.controller:MamotoApiController', path_prefix='/api{ver:/3|}', ver='/3') as m: + with SubMapper(map, controller='ckanext.odsh.controller:OdshApiController', path_prefix='/api{ver:/3|}', ver='/3') as m: m.connect('/action/{logic_function}', action='action', conditions=GET_POST) with SubMapper(map, controller='ckanext.odsh.controller:OdshFeedController') as m: