How to use the ckan.plugins.toolkit.get_action 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 ckan / ckanext-pages / ckanext / pages / controller.py View on Github external
def group_edit(self, id, page=None, data=None, errors=None, error_summary=None):
        self._template_setup_group(id)
        if page:
            page = page[1:]
        _page = p.toolkit.get_action('ckanext_pages_show')(
            data_dict={'org_id': p.toolkit.c.group_dict['id'],
                       'page': page}
        )
        if _page is None:
            _page = {}

        if p.toolkit.request.method == 'POST' and not data:
            data = p.toolkit.request.POST
            items = ['title', 'name', 'content', 'private']
            # update config from form
            for item in items:
                if item in data:
                    _page[item] = data[item]
            _page['org_id'] = p.toolkit.c.group_dict['id']
            _page['page'] = page
            try:
github ckan / ckanext-basiccharts / ckanext / basiccharts / plugin.py View on Github external
def _view_data(resource_view):
    data = {
        'resource_id': resource_view['resource_id'],
        'limit': int(resource_view.get('limit', 100))
    }

    filters = resource_view.get('filters', {})
    for key, value in parse_filter_params().items():
        filters[key] = value
    data['filters'] = filters

    fields = resource_view.get('fields')
    if fields:
        data['fields'] = convert_to_string(fields).split(',')

    result = p.toolkit.get_action('datastore_search')({}, data)
    return result
github NaturalHistoryMuseum / ckanext-nhm / ckanext / nhm / commands / datastore.py View on Github external
def _get_datastore_or_fail(self, resource_id):
        '''Get the resource from the datastore - if not found, throw an exception.

        :param resource_id: the ID of the resource to try to retrieve

        '''
        data = {
            u'resource_id': resource_id, u'limit': 0
            }

        try:
            return toolkit.get_action(u'datastore_search')({}, data)
        except toolkit.ObjectNotFound:
            raise self.BadCommand(u'Datastore resource %s does not exist' % resource_id)
github NaturalHistoryMuseum / ckanext-ldap / ckanext / ldap / commands / ldap.py View on Github external
def setup_org(self):

        # Get the organisation all users will be added to
        organization_id = pylons.config['ckanext.ldap.organization.id']

        try:
            toolkit.get_action('organization_show')(self.context, {'id': organization_id})
        except logic.NotFound:
            toolkit.get_action('organization_create')(self.context, {'id': organization_id, 'name': organization_id})
github ckan / ckanext-qa / ckanext / qa / tasks.py View on Github external
def _update_search_index(package_id):
    '''
    Tells CKAN to update its search index for a given package.
    '''
    from ckan import model
    from ckan.lib.search.index import PackageSearchIndex
    package_index = PackageSearchIndex()
    context_ = {'model': model, 'ignore_auth': True, 'session': model.Session,
                'use_cache': False, 'validate': False}
    package = toolkit.get_action('package_show')(context_, {'id': package_id})
    package_index.index_package(package, defer_commit=False)
    log.info('Search indexed %s', package['name'])
github ckan / ckanext-issues / ckanext / issues / controller / controller.py View on Github external
params = locals().copy()

    # convert per_page, page parameters to api limit/offset
    limit = per_page
    offset = (page - 1) * limit
    params.pop('page', None)
    params.pop('per_page', None)

    # fetch only the results for the current page
    params.update({
        'include_count': False,
        'limit': limit,
        'offset': offset,
    })

    results_for_current_page = toolkit.get_action('issue_search')(
        data_dict=params
    )
    issues = results_for_current_page['results']

    # fetch the total count of all the search results without dictizing
    params['include_count'] = True
    params['include_results'] = False
    params.pop('limit', None)
    params.pop('offset', None)
    all_search_results = toolkit.get_action('issue_search')(data_dict=params)
    issue_count = all_search_results['count']

    pagination = Pagination(page, limit, issue_count)

    template_variables = {
        'issues': issues,
github ckan / ckanext-issues / ckanext / issues / controller / controller.py View on Github external
def assign(self, dataset_id, issue_number):
        dataset = self._before_dataset(dataset_id)
        if request.method == 'POST':
            try:
                assignee_id = request.POST.get('assignee')
                assignee = toolkit.get_action('user_show')(
                    data_dict={'id': assignee_id})
            except toolkit.ObjectNotFound:
                h.flash_error(_('User {0} does not exist'.format(assignee_id)))
                return p.toolkit.redirect_to('issues_show',
                                             issue_number=issue_number,
                                             dataset_id=dataset_id)

            try:
                issue = toolkit.get_action('issue_update')(
                    data_dict={
                        'issue_number': issue_number,
                        'assignee_id': assignee['id'],
                        'dataset_id': dataset_id
                    }
                )
github ckan / ckanext-pages / ckanext / pages / controller.py View on Github external
def _template_setup_org(self, id):
        if not id:
            return
        # we need the org for the rest of the page
        context = {'for_view': True}
        try:
            p.toolkit.c.group_dict = p.toolkit.get_action('organization_show')(context, {'id': id})
        except p.toolkit.ObjectNotFound:
            p.toolkit.abort(404, _('Organization not found'))
        except p.toolkit.NotAuthorized:
            p.toolkit.abort(401, _('Unauthorized to read organization %s') % id)
github NaturalHistoryMuseum / ckanext-nhm / ckanext / nhm / routes / object.py View on Github external
'''
    Return RDF view of object.

    :param uuid: the object's uuid
    :param _format: the format requested
    :param version: the version of the record to retrieve, or None if the current
                    version is desired
    :return: the data to display
    '''
    data_dict = {
        u'uuid': uuid,
        u'format': _format,
        u'version': version,
    }
    try:
        result = toolkit.get_action(u'object_rdf')(_context(), data_dict)
        return Response(result, mimetype=CONTENT_TYPES[_format])
    except toolkit.ValidationError, e:
        toolkit.abort(409, str(e))
github frictionlessdata / ckanext-datapackager / ckanext / datapackager / logic / action / delete.py View on Github external
raise toolkit.ValidationError(e)
    if errors:
        raise toolkit.ValidationError(errors)

    resource_id = data_dict.pop('resource_id')
    index = data_dict['index']

    schema_ = toolkit.get_action('resource_schema_show')(context,
        {'resource_id': resource_id})

    new_fields = [field for field in schema_['fields']
                  if field['index'] != index]
    assert len(new_fields) == len(schema_['fields']) - 1
    schema_['fields'] = new_fields

    resource_dict = toolkit.get_action('resource_show')(context,
                                       {'id': resource_id})

    toolkit.get_action('resource_update')(context,
        {'id': resource_id, 'url': resource_dict['url'],
         'name': resource_dict['name'], 'schema': json.dumps(schema_)})