[ckan-dev] Hierarchical folder structure for a dataset

Damian Steer d.steer at bris.ac.uk
Tue Aug 15 14:34:55 UTC 2017


On 15/08/17 00:19, Prashant Gupta wrote:
> Hi Damian
> 
> Thanks for sharing this info.
> 
> I would be interested to know if the code for this customization, especially code for displaying the folder structure as tree, is publicly available.

You can see the relevant code here:

<https://bitbucket.org/snippets/databris/oj5X6n>

Sorry, it's grown organically :-/

Explanation: this adds two helper functions

DataBrisUI_get_datatree(pkg) - get_package_tree(pkg)
DataBrisUI_top_package(pkg.id) - get_top_level_package(id)

(I don't know why we pass the pkg in the first case and the id in the 
latter :-)

The latter will return the top level package holding the given package, 
which we use for linking back to the top. In that function you'll see we 
stash the result in a special database table, to avoid calculating it 
each time.

The former is what you're interested in.

Once again we stash the result (the actual, dodgy html) in a database 
table to speed things up.

The main thing of interest here is get_child_packages(id). We use 
package_search to find the children:

     p.toolkit.get_action('package_search')(data_dict={'fq': 'child_of:' 
+ id, 'rows': 1000})['results']

The reason for that is that we found the standard api call very slow (at 
the time). This solr search was much quick, and returned everything we 
needed.

Damian

-- 
Damian Steer
Senior Technical Researcher
Research IT
+44 (0) 117 39 41724



More information about the ckan-dev mailing list