Use _get_group as a fallback for remote orgs

First try to get a remote org from the remote Action API, if this fails
try to use the old rest api call, which works on older CKAN versions.

Only if both options fail, its currently not possible to get the remote
organization.
This commit is contained in:
Stefan Oderbolz 2015-01-14 00:10:27 +01:00
parent f214577872
commit 0fd38e0e54
1 changed files with 8 additions and 1 deletions

View File

@ -337,7 +337,14 @@ class CKANHarvester(HarvesterBase):
log.info('Organization %s is not available' % remote_org) log.info('Organization %s is not available' % remote_org)
if remote_orgs == 'create': if remote_orgs == 'create':
try: try:
org = self._get_organization(harvest_object.source.url, remote_org) try:
org = self._get_organization(harvest_object.source.url, remote_org)
except:
# fallback if remote CKAN exposes organizations as groups
# this especially targets older versions of CKAN
log.debug('_get_organization() failed, now trying _get_group()')
org = self._get_group(harvest_object.source.url, remote_org)
for key in ['packages', 'created', 'users', 'groups', 'tags', 'extras', 'display_name', 'type']: for key in ['packages', 'created', 'users', 'groups', 'tags', 'extras', 'display_name', 'type']:
org.pop(key, None) org.pop(key, None)
get_action('organization_create')(context, org) get_action('organization_create')(context, org)