Access package_id from dict resource in CKAN

I am looking for a way to find package_id for a resource in CKAN. I access the resource using the resource_show action:

 resource_dict = toolkit.get_action("resource_show")(context, {"id": "my-resource"}) 

As a result, dict does not tell me which package belongs to the resource. This tells me:

 resource_dict.get("package_id", None) == None # <<< True resource_dict["resource_group_id"] = "some-uuid" 

And I can see in my database that resource_group has a package_id attribute. However, there seems to be no resource_group_show action.

Is there any other way to transition from a dict resource to its parent package?

Thanks!

+4
source share
3 answers

In CKAN 2.3 and later, package_id returned when the resource_show API is called.

+1
source

You're right, unfortunately, the current version of CKAN (2.2.1) does not include package_id when you call resource_show, and there is no call to resource_group_show. If you are writing an extension, you can work around this by running a direct database query:

 SELECT resource_group.package_id FROM resource, resource_group WHERE resource.id='<resource_id>' AND resource.resource_group_id=resource_group.id; 

If you are trying to get package_id using the API, the only way to find it is to look from top to bottom, call package_list, then package_show for each, until you find the one that contains the corresponding resource_id.

0
source

You must use the revision_show method.

 import ckanapi ckan = ckanapi.RemoteCKAN('url', apikey='key') resource = ckan.action.resource_show(id='resource_id') revision_id = resource['revision_id'] revision = ckan.action.revision_show(id=revision_id) package_id = revision['packages'][0] 
0
source

Source: https://habr.com/ru/post/1491015/


All Articles