Only try to create/match a organization if there is a remote_org

This commit is contained in:
Stefan Oderbolz 2013-10-11 18:08:32 +02:00
parent dd1acd0c6b
commit 8b5d70c6fe
1 changed files with 18 additions and 17 deletions

View File

@ -308,23 +308,24 @@ class CKANHarvester(HarvesterBase):
validated_org = None
remote_org = package_dict['owner_org']
context = {'model': model, 'session': Session, 'user': 'harvest'}
try:
data_dict = {'id': remote_org}
org = get_action('organization_show')(context, data_dict)
validated_org = org['id']
except NotFound, e:
log.info('Organization %s is not available' % remote_org)
if remote_orgs == 'create':
try:
org = self._get_group(harvest_object.source.url, remote_org)
for key in ['packages', 'created', 'users', 'groups', 'tags', 'extras', 'display_name', 'type']:
org.pop(key, None)
get_action('organization_create')(context, org)
log.info('Organization %s has been newly created' % remote_org)
validated_org = org['id']
except:
log.error('Could not get remote org %s' % remote_org)
if remote_org:
try:
data_dict = {'id': remote_org}
org = get_action('organization_show')(context, data_dict)
validated_org = org['id']
except NotFound, e:
log.info('Organization %s is not available' % remote_org)
if remote_orgs == 'create':
try:
org = self._get_group(harvest_object.source.url, remote_org)
for key in ['packages', 'created', 'users', 'groups', 'tags', 'extras', 'display_name', 'type']:
org.pop(key, None)
get_action('organization_create')(context, org)
log.info('Organization %s has been newly created' % remote_org)
validated_org = org['id']
except:
log.error('Could not get remote org %s' % remote_org)
package_dict['owner_org'] = validated_org