Last active
September 10, 2019 00:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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