[ckan-dev] IDataSetForm.setup_template_variables vs. IPackageController.before_view

Sean Hammond sean.hammond at okfn.org
Wed Jun 6 09:29:17 UTC 2012


> It seems that either function can be used to modify 'pkg_dict' which
> is then passed to the templates to customize what is rendered.
> 
> Which ones should be used and when?

You can use your extension to test exactly when each function does and
does not get called, but:

It looks like setup_template_variables() is only called in a couple of
places, when creating a new dataset and when editing a dataset (which
makes sense as it's part of the IDatasetForm plugin which only gets used
when there's a form involved). I'm not familiar with this function, but
looking at the core extensions in ckan/ckanext, the method is used by
the organizations extension to implement its custom dataset create/edit
forms.

before_view() is called whenever a package is dictized, including on the
package read page and (I think) also on package list pages (e.g.
dataset search results listings). But note that before_view() does not
get called when accessing CKAN via the API, only when via the web UI.
The purpose of before_view() is to allow extensions to modify the
package dict before anything gets displayed to the user. For example, it
is used by the multilingual extension to translate dataset fields like
title, description, etc. into the user's selected language before
displaying them.

Hope that helps




More information about the ckan-dev mailing list