How to use the ckan.plugins function in ckan

To help you get started, we’ve selected a few ckan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frictionlessdata / ckanext-datapackager / ckanext / datapackager / plugin.py View on Github external
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
import ckanext.datapackager.logic.action.create
import ckanext.datapackager.logic.action.get


class DataPackagerPlugin(plugins.SingletonPlugin):
    '''Plugin that adds importing/exporting datasets as Data Packages.
    '''
    plugins.implements(plugins.IActions)
    plugins.implements(plugins.IConfigurer)
    plugins.implements(plugins.IRoutes, inherit=True)

    def update_config(self, config):
        toolkit.add_template_directory(config, 'templates')

    def before_map(self, map_):
        map_.connect(
            'import_datapackage',
            '/import_datapackage',
            controller='ckanext.datapackager.controllers.datapackage:DataPackageController',
            action='new',
            conditions=dict(method=['GET']),
github NaturalHistoryMuseum / ckanext-nhm / ckanext / nhm / controllers / page.py View on Github external
def about_data_usage(self):
        return p.toolkit.render('about/data_usage.html', {'title': 'Guidelines for data use'})
github alexandrainst / ckanext-realtime / ckanext / realtime / logic / auth.py View on Github external
def realtime_auth(context, data_dict, privilege='resource_update'):
    user = context.get('user')
    authorized = p.toolkit.check_access(privilege, context, data_dict)

    if not authorized:
        return {
            'success': False,
            'msg': p.toolkit._('User {0} not authorized to update resource {1}'
                    .format(str(user), data_dict['resource_id']))
        }
    else:
        return {'success': True}
github ckan / ckanext-qa / ckanext / qa / commands.py View on Github external
task_id = make_uuid()
                    task_status = {
                        'entity_id': resource['id'],
                        'entity_type': u'resource',
                        'task_type': u'qa',
                        'key': u'celery_task_id',
                        'value': task_id,
                        'error': u'',
                        'last_updated': datetime.datetime.now().isoformat()
                    }
                    task_context = {
                        'model': model,
                        'user': user.get('name')
                    }

                    p.toolkit.get_action('task_status_update')(task_context, task_status)
                    tasks.update.apply_async(args=[context, data], task_id=task_id)

        elif cmd == 'clean':
            self.log.error('Command "%s" not implemented' % (cmd,))

        else:
            self.log.error('Command "%s" not recognized' % (cmd,))
github ckan / ckanext-pages / ckanext / pages / plugin.py View on Github external
from pylons import config
import ckan.plugins.toolkit as toolkit
ignore_missing = toolkit.get_validator('ignore_missing')

import ckan.plugins as p
import ckan.lib.helpers as h
import actions
import auth

if toolkit.check_ckan_version(min_version='2.5'):
    from ckan.lib.plugins import DefaultTranslation

    class PagesPluginBase(p.SingletonPlugin, DefaultTranslation):
        p.implements(p.ITranslation, inherit=True)
else:
    class PagesPluginBase(p.SingletonPlugin):
        pass

log = logging.getLogger(__name__)


def build_pages_nav_main(*args):

    about_menu = toolkit.asbool(config.get('ckanext.pages.about_menu', True))
    group_menu = toolkit.asbool(config.get('ckanext.pages.group_menu', True))
    org_menu = toolkit.asbool(config.get('ckanext.pages.organization_menu', True))

    # Different CKAN versions use different route names - gotta catch em all!
    about_menu_routes = ['about', 'home.about']
    group_menu_routes = ['group_index', 'home.group_index']
    org_menu_routes = ['organizations_index', 'home.organizations_index']
github ckan / ckanext-drupal7 / ckanext / drupal7 / plugin.py View on Github external
def user_reset(context, data_dict):
    msg = p.toolkit._('Users cannot reset passwords.')
    return _no_permissions(context, msg)


@logic.auth_sysadmins_check
def request_reset(context, data_dict):
    msg = p.toolkit._('Users cannot reset passwords.')
    return _no_permissions(context, msg)


class Drupal7Plugin(p.SingletonPlugin):

    p.implements(p.IAuthenticator, inherit=True)
    p.implements(p.IRoutes, inherit=True)
    p.implements(p.IAuthFunctions, inherit=True)
    p.implements(p.IConfigurer)
    p.implements(p.IConfigurable)
    p.implements(p.ITemplateHelpers)

    drupal_session_name = None

    def get_helpers(self):
        return {'ckanext_drupal7_domain': self.get_domain}

    def get_domain(self):
        return self.domain

    @staticmethod
    def update_config(config):
        p.toolkit.add_template_directory(config, 'templates')
github vrk-kpa / api-catalog / ckanext / ckanext-apicatalog_routes / ckanext / apicatalog_routes / plugin.py View on Github external
import auth


def admin_only(context, data_dict=None):
    return {'success': False, 'msg': 'Access restricted to system administrators'}

def set_repoze_user(user_id):
    '''Set the repoze.who cookie to match a given user_id'''
    if 'repoze.who.plugins' in request.environ:
        rememberer = request.environ['repoze.who.plugins']['friendlyform']
        identity = {'repoze.who.userid': user_id}
        response.headerlist += rememberer.remember(request.environ, identity)


class Apicatalog_RoutesPlugin(ckan.plugins.SingletonPlugin, ckan.lib.plugins.DefaultPermissionLabels):
    ckan.plugins.implements(ckan.plugins.IRoutes, inherit=True)
    ckan.plugins.implements(ckan.plugins.IAuthFunctions)
    ckan.plugins.implements(ckan.plugins.IPermissionLabels)
    ckan.plugins.implements(ckan.plugins.IPackageController, inherit=True)

    # IRoutes

    def before_map(self, m):
        controller = 'ckanext.apicatalog_routes.plugin:Apicatalog_RevisionController'
        m.connect('/revision', action='index', controller=controller)
        m.connect('/revision/list', action='list', controller=controller)
        m.connect('/revision/diff/{id}', action='diff', controller=controller)

        health_controller = 'ckanext.apicatalog_routes.health:HealthController'
        m.connect('/health', action='check', controller=health_controller)
github vrk-kpa / api-catalog / ckanext / ckanext-fluentall / ckanext / fluentall / plugin.py View on Github external
# IGroupController
    def before_view(self, pkg_dict):
        return super(FluentallGroupPlugin, self).before_view(pkg_dict)


class FluentallOrganizationPlugin(FluentallLanguagePlugin):
    plugins.implements(plugins.IOrganizationController, inherit=True)

    # IOrganizationController

    def before_view(self, pkg_dict):
        return super(FluentallOrganizationPlugin, self).before_view(pkg_dict)


class FluentallResourcePlugin(FluentallLanguagePlugin):
    plugins.implements(plugins.IResourceController, inherit=True)

    # IResourceController

    def before_view(self, pkg_dict):
        return super(FluentallResourcePlugin, self).before_view(pkg_dict)

    def _ignore_field(self, key):
        return key == 'tracking_summary'


class FluentallPackagePlugin(FluentallLanguagePlugin):
    plugins.implements(plugins.IPackageController, inherit=True)

    # IPackageController

    def before_view(self, pkg_dict):