From c18d9dc3af3a708e6435efb95ef760fe6858b917 Mon Sep 17 00:00:00 2001 From: amercader Date: Tue, 22 Oct 2013 16:24:43 +0100 Subject: [PATCH] [#71] CKAN harvester: Add datasets to source organization If the harvest source belongs to an organization, new datasets should be added to it. This is already the case in the spatial harvesters. The remote orgs logic has been kept, with the difference that if for some reason the remote org can not be assigned, the local one is used. If the source does not have an organization, none is added. --- ckanext/harvest/harvesters/ckanharvester.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ckanext/harvest/harvesters/ckanharvester.py b/ckanext/harvest/harvesters/ckanharvester.py index 884bd19..5f67518 100644 --- a/ckanext/harvest/harvesters/ckanharvester.py +++ b/ckanext/harvest/harvesters/ckanharvester.py @@ -296,10 +296,17 @@ class CKANHarvester(HarvesterBase): package_dict['groups'] = validated_groups + context = {'model': model, 'session': Session, 'user': 'harvest'} + + # Local harvest source organization + source_dataset = get_action('package_show')(context, {'id': harvest_object.source.id}) + local_org = source_dataset.get('owner_org') + remote_orgs = self.config.get('remote_orgs', None) + if not remote_orgs in ('only_local', 'create'): - # Ignore remote groups - package_dict.pop('owner_org', None) + # Assign dataset to the source organization + package_dict['owner_org'] = local_org else: if not 'owner_org' in package_dict: package_dict['owner_org'] = None @@ -307,8 +314,7 @@ class CKANHarvester(HarvesterBase): # check if remote org exist locally, otherwise remove validated_org = None remote_org = package_dict['owner_org'] - context = {'model': model, 'session': Session, 'user': 'harvest'} - + if remote_org: try: data_dict = {'id': remote_org} @@ -327,7 +333,7 @@ class CKANHarvester(HarvesterBase): except: log.error('Could not get remote org %s' % remote_org) - package_dict['owner_org'] = validated_org + package_dict['owner_org'] = validated_org or local_org # Set default groups if needed default_groups = self.config.get('default_groups', [])