Skip to content
Snippets Groups Projects
plugin.py 1.96 KiB
Newer Older
  • Learn to ignore specific revisions
  • root's avatar
    root committed
    
    from ckan.lib.plugins import DefaultTranslation, DefaultDatasetForm
    
    import ckan.plugins as plugins
    import ckan.plugins.toolkit as toolkit
    
    root's avatar
    root committed
    import helpers as collection_helpers
    from routes.mapper import SubMapper
    
    class CollectionsPlugin(plugins.SingletonPlugin, DefaultDatasetForm):
        plugins.implements(plugins.IDatasetForm, inherit=True)
        plugins.implements(plugins.IRoutes, inherit=True)
        plugins.implements(plugins.ITemplateHelpers)
    
    
        # IDataSetForm
        def package_types(self):
            return ('collection', )
        
        def is_fallback(self):
            return False
    
        
        def read_template(self):
            return 'package/collection_read.html'
    
    root's avatar
    root committed
    
        
        # IRoutes    
        def before_map(self, map):
    
            map.connect(
                '/collection/{id}/aktuell',
                controller='ckanext.odsh.collection.controller:LatestDatasetController',
                action='latest_dataset'
            )
    
            map.connect(
    
                '/collection/{id}/aktuell.{resource_format}',
    
    root's avatar
    root committed
                controller='ckanext.odsh.collection.controller:LatestRecourcesController',
                action='latest_resource'
            )
    
            with SubMapper(
                map, 
                controller='ckanext.odsh.collection.controller:LatestDatasetController', 
                path_prefix='/collection/'
            ) as m:
                m.connect('latest', '{id}/aktuell', action='latest')
    
                m.connect('latest_resource', '{id}/aktuell.{resource_format}', action='latest_resource')  
    
    root's avatar
    root committed
            return map
    
        def after_map(self, map):
            return map
    
        
        # ITemplateHelpers
        def get_helpers(self):
            # Template helper function names should begin with the name of the
            # extension they belong to, to avoid clashing with functions from
            # other extensions.
    
            return {
    
                'get_collection': collection_helpers.get_collection,
                'get_collection_info': collection_helpers.get_collection_info,
                'url_from_id': collection_helpers.url_from_id,
    
    root's avatar
    root committed
            }