Created
April 10, 2012 16:45
-
-
Save seanh/2352758 to your computer and use it in GitHub Desktop.
Example CKAN extension with custom package controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ckan.plugins import IRoutes, implements, SingletonPlugin | |
from ckan.controllers.package import PackageController | |
from ckan.config.routing import SubMapper | |
class TestPackageControllerPlugin(SingletonPlugin): | |
implements(IRoutes, inherit=True) | |
def before_map(self, map): | |
# Default mappings copied from ckan/config/routing.py that we want to preserve. | |
with SubMapper(map, controller='package') as m: | |
m.connect('/dataset/{action}', | |
requirements=dict(action='|'.join([ | |
'list', | |
'new', | |
'autocomplete', | |
'search' | |
])) | |
) | |
m.connect('/dataset/{action}/{id}/{revision}', action='read_ajax', | |
requirements=dict(action='|'.join([ | |
'read', | |
'edit', | |
'authz', | |
'history', | |
])) | |
) | |
m.connect('/dataset/{action}/{id}', | |
requirements=dict(action='|'.join([ | |
'edit', | |
'editresources', | |
'authz', | |
'history', | |
'read_ajax', | |
'history_ajax', | |
])) | |
) | |
m.connect('/dataset/{id}.{format}', action='read') | |
m.connect('/dataset/{id}/resource/{resource_id}', action='resource_read') | |
# Our new custom mapping. | |
map.connect('/dataset/{id}', | |
controller='ckanext.testpackagecontroller.plugin:TestPackageController', | |
action='read', | |
) | |
return map | |
class TestPackageController(PackageController): | |
def read(self, id): | |
return 'foobar' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know what is the correct template to replace
/dataset/
? Is it/{dataset_type}/
or/{type}/