[ckan-dev] Affecting previews in a plugin

Sean Hammond sean.hammond at okfn.org
Wed Feb 27 16:41:20 UTC 2013


> I'm trying to write a plugin that affects if a dataset is
> preview-able. Specifically  if a fairly large dataset is linked then
> CKAN will attempt to preview this via the dataproxy and that will time
> out. My aim is to use something in the background to follow the urls
> (and redirect chains) of linked packages and eventually do a HEAD
> request and see if there is a content-length.
> 
> So this prompts a couple of questions:
> 
> 1. How to hook into the preview rendering machenery. I can't  use
> IResourcePreview as I'll step on the toes of other packages. I looked
> for a while at IPackageController but it looks like there's no means to
> get into the resource_datapreview method on PackageController. So that
> leaves me with a change to ckan core to add a new extension point (yuck)
> or monkey patching (yuck squared).

I would probably try and do this as a straight change to ckan core, not
as an extension. I don't think this can be done by an extension, at
least not in a nice way. Have you looked at doing it in core?

> 2. I'll need to store the dataset sizes somewhere. I can't find any docs
> on creating database tables in the extension docs - is there an example
> of an extension that creates its own db tables somewhere?

A couple of extensions do this by importing ckan.model directly. The
general rule is that adding your own tables is okay, but an extension
adding columns to existing tables or anything like that is a bad idea.
Also I don't think your extension's tables should have foreign keys
against core tables or anything like that.

Examples:

https://github.com/okfn/ckanext-spatial/tree/master/ckanext/spatial/model

https://github.com/okfn/ckanext-harvest/tree/master/ckanext/harvest/model

However, as I said, this whole thing might be better done in core




More information about the ckan-dev mailing list