Skip to content

Instantly share code, notes, and snippets.

@salsa-nathan
Last active September 10, 2019 00:48
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 salsa-nathan/3e38774f7f3e4d3582eec3774b055643 to your computer and use it in GitHub Desktop.
Save salsa-nathan/3e38774f7f3e4d3582eec3774b055643 to your computer and use it in GitHub Desktop.
CKAN - automatically add new resources to the top position of the resource order
...
import logging
log = logging.getLogger(__name__)
class YourPlugin(plugins.SingletonPlugin):
...
plugins.implements(plugins.IResourceController, inherit=True)
...
def after_create(self, context, data_dict):
# Set the resource position order for this (latest) resource to first
resource_id = data_dict.get('id', None)
package_id = data_dict.get('package_id', None)
if resource_id and package_id:
try:
toolkit.get_action('package_resource_reorder')(context, {'id': package_id, 'order': [resource_id]})
except Exception, e:
log.error(str(e))
return data_dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment