Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmalex07/b395b2671ac4f5afda34 to your computer and use it in GitHub Desktop.
Save drmalex07/b395b2671ac4f5afda34 to your computer and use it in GitHub Desktop.
Problem (?) with CKAN authorization on packages in a custom (not active or draft) state and not owned by any organization.
import ckanapi
site_url = 'http://ckan-1.localdomain:5000/'
api_key = 'a93612c7-fe59-4453-8763-e568409b282b'
client = ckanapi.RemoteCKAN(site_url)
client.apikey = api_key
data = {
'name': 'hello-1',
'title': u'Hello (1)',
'notes': u'I say Hello, you say Goodbye',
}
# The above results in the package being created, but left unreadable for its creator
pkg_dict = client.action.package_create(**data)
def create_package_schema(self, schema):
schema = super(DatasetForm, self).create_package_schema()
# Install field validators/converters ...
# Implement some logic that computes package's next state
def compute_next_state(key, data, errors, context):
if data[('name',)].startswith('hello'):
state = data[('state',)] = 'moderated'
schema['__after'].append(compute_next_state)
return schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment