From a726c003cfaac00fabcccacccd9c89a7018d909f Mon Sep 17 00:00:00 2001 From: dwcaraway Date: Mon, 2 Dec 2013 10:58:39 -0500 Subject: [PATCH] Addresses https://github.com/GSA/enterprise-data-inventory/issues/51 where we have the server returning an HTTP 500 error when the datasets does not have a 'public_access_level' extras field. Modified so that if this extra isn't found, we default to public access level. --- ckanext/datajson/plugin.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ckanext/datajson/plugin.py b/ckanext/datajson/plugin.py index b44eaf3b..d77cf52f 100644 --- a/ckanext/datajson/plugin.py +++ b/ckanext/datajson/plugin.py @@ -227,8 +227,8 @@ def make_json(): #Create data.json only using public and public-restricted datasets, datasets marked non-public are not exposed for pkg in packages: extras = dict([(x['key'], x['value']) for x in pkg['extras']]) - if not (re.match(r'[Nn]on-public', extras['public_access_level'])): - output.append(make_datajson_entry(pkg)); + if not (re.match(r'[Nn]on-public', extras.get('public_access_level', 'Public'))): + output.append(make_datajson_entry(pkg)) return output def make_edi(owner_org): @@ -236,8 +236,8 @@ def make_edi(owner_org): packages = p.toolkit.get_action("current_package_list_with_resources")(None, {}) output = [] for pkg in packages: - if pkg['owner_org']==owner_org: - output.append(make_datajson_entry(pkg)); + if pkg['owner_org'] == owner_org: + output.append(make_datajson_entry(pkg)) return json.dumps(output) def make_pdl(owner_org): @@ -247,8 +247,9 @@ def make_pdl(owner_org): #Create data.json only using public datasets, datasets marked non-public are not exposed for pkg in packages: extras = dict([(x['key'], x['value']) for x in pkg['extras']]) - if pkg['owner_org']==owner_org and not (re.match(r'[Nn]on-public', extras['public_access_level'])): - output.append(make_datajson_entry(pkg)); + if pkg['owner_org'] == owner_org \ + and not (re.match(r'[Nn]on-public', extras.get('public_access_level', 'Public'))): + output.append(make_datajson_entry(pkg)) return json.dumps(output) # TODO commenting out enterprise data inventory for right now