How to use ckan - 10 common examples

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-issues / test / test_logic.py View on Github external
model.Session.add(self.otherUser)
        model.Session.commit()
        self.dataset = model.Package.get('annakarenina')
        # test fixture
        self.context = {
            'model': model,
            'auth_user_obj': self.user,
            'user': self.user.name
        }
        # fixture issue
        self.issue = logic.get_action('issue_create')(self.context, {
            'title': 'General test issue',
            'description': 'Abc\n\n## Section',
            'dataset_id': self.dataset.id
        })
        self.issue2 = logic.get_action('issue_create')(self.context, {
            'title': 'General test issue 2',
            'description': '',
            'dataset_id': self.dataset.id
        })
github ckan / ckanext-qa / tests / test_tasks.py View on Github external
def _test_resource(self, url='anything', format='TXT', archived=True, cached=True, license_id='uk-ogl'):
        pkg = {'license_id': license_id,
               'resources': [
                   {'url': url, 'format': format, 'description': 'Test'}
               ]}
        pkg = ckan_factories.Dataset(**pkg)
        res_id = pkg['resources'][0]['id']
        if archived:
            archival = Archival.create(res_id)
            archival.cache_filepath = __file__ if cached else None  # just needs to exist
            archival.updated = TODAY
            model.Session.add(archival)
            model.Session.commit()
        return model.Resource.get(res_id)
github ckan / ckanext-qa / tests / test_archive.py View on Github external
def decorated(*args, **kwargs):
            args, base_url = args[:-1], args[-1]
            Session.remove()
            rev = repo.new_revision()
            package = Package(name=TEST_PACKAGE_NAME)
            Session.add(package)
            resources = [
                Resource(
                    description=u'Resource #%d' % (ix,),
                    url=(base_url + url).decode('ascii')
                )
                for ix, url in enumerate(resource_urls)
            ]
            for r in resources:
                Session.add(r)
                package.resources.append(r)
            repo.commit()

            context = {
                'model': model, 'session': model.Session, 'id': package.id
            }
            package_dict = package_dictize(package, context)

            try:
github ckan / ckanext-issues / test / test_wui.py View on Github external
def test_issue_comment_new_post(self):
        ourissue = logic.get_action('issue_create')(self.context, {
            'title': 'General test issue',
            'description': 'Abc\n\n## Section',
            'dataset_id': self.dataset.id
        })
        offset = url_for('issues_comments', package_id=self.dataset.name,
                id=ourissue['id'])
        data = {
            'comment': ''
            }
        res = self.app.post(offset,
                params=data,
                status=[302],
                extra_environ=self.extra_environ_tester
                )
        issueUpdate = logic.get_action('issue_show')(self.context, {
            'id': ourissue['id']
github ckan / ckanext-archiver / tests / test_archiver.py View on Github external
    @classmethod
    def setup_class(cls):
        reset_db()
        archiver_model.init_tables(model.meta.engine)

        cls.temp_dir = tempfile.mkdtemp()

        cls.config = config.__file__
github ckan / ckanext-issues / test / test_wui.py View on Github external
def setup_class(self):
        # Return a test app with the custom config.
        app = ckan.config.middleware.make_app(config['global_conf'], **config)
        self.app = webtest.TestApp(app)
        ckan.plugins.load('issues')
        ckan.tests.CreateTestData.create()
        self.sysadmin_user = ckan.model.User.get('testsysadmin')
        self.dataset = model.Package.get('annakarenina')
        self.extra_environ_tester = {'REMOTE_USER': 'tester'}
        self.context = {
            'model': model,
            'auth_user_obj': self.sysadmin_user,
            'user': self.sysadmin_user.name
        }
        self.issue = logic.get_action('issue_create')(self.context, {
            'title': 'General test issue',
            'description': 'Abc\n\n## Section',
            'dataset_id': self.dataset.id
        })
        self.comment = logic.get_action('issue_comment_create')(self.context, {
            'issue_id': self.issue['id'],
            'comment': 'Test comment'
            })
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
# encoding: utf-8
#
# This file is part of ckanext-nhm
# Created by the Natural History Museum in London, UK

import logging

from ckanext.datastore.db import _get_engine

import ckan.model as model
from ckan.plugins import toolkit

log = logging.getLogger()


class DatastoreCommand(toolkit.CkanCommand):
    '''Datastore commands, for modifying CKAN datastore resources
    
    Commands:
    
        purge-all - Delete all datasets and datastore tables
        paster datastore purge-all -c /etc/ckan/default/development.ini
    
        replace - Update datastore aliases
        paster datastore replace -i [resource_id] -t [table] -c /etc/ckan/default/development.ini
            Required param: ID of the datastore resource to update
            Required param: str alias

    '''
    summary = __doc__.split(u'\n')[0]
    usage = __doc__
github datagovuk / ckanext-os / ckanext / os / controllers / widgets.py View on Github external
url = request.params.get('url')

        # Check parameter
        if not (url):
            response.status_int = 400
            return 'Missing url parameter'

        # Check URL is in CKAN (otherwise we are an open proxy)
        base_url = url.split('?')[0] if '?' in url else url
        if base_url == urljoin(g.site_url, '/data/wfs'):
            # local WFS service
            return self._read_url(url, post_data=request.body,
                                  content_type='application/xml')
        else:
            # WMS
            query = model.Session.query(model.Resource) \
                         .filter(model.Resource.url.like(base_url + '%'))

            if query.count() == 0:
                response.status_int = 403
                return 'WMS URL not known: %s' % base_url

        # Correct basic errors in the WMS URL
        try:
            url = self.wms_url_correcter(url)
        except ValidationError, e:
            response.status_int = 400
            log.warning('WMS Preview proxy received invalid url: %r', url)
            return 'Invalid URL: %s' % str(e)

        content = self._read_url(url)
        if not content: