[ckan-dev] Custom fields that are arrays or objects with fields

Ian Ward ian at excess.org
Thu Oct 30 15:31:07 UTC 2014


On Thu, Oct 30, 2014 at 11:13 AM, Renato Guevara
<guevara.renato at gmail.com> wrote:
> Ian,
>
> Thank you for your response.  I'm looking through both ckanext-scheming and
> ckanext-fluent, but I'm a bit confused on how you use them.  I get the
> concept of how ckanext-scheming is used to define your own json schema.  So,
> when you use the ckanext-fluent plugin, how do you modify ckanext-scheming
> to use fluent?  In addition to that, I see that ckanext-scheming implements

You add the fluent plugin and include the fluent validators and
template snippets where you wan them in your scheming schema.

> the IDatasetForm class, but doesn't implement the package_create/modify/show
> functions required.  Does that mean that it is added by the user?  I'm a bit
> fuzzy on that.  Would you be able to help me run through the steps.

Yes, to use ckanext-scheming you would add it (scheming_datasets) to
your plugins in your ini file. The scheming_datasets plugin implements
the validate method of the IDatasetForm interface which covers all the
create/modify/show cases.

> For example, before I knew about this plugin, I had written the following
> plugin to add my customized fields.
[...]

The idea of scheming is to allow this kind of plugin to be written as
mostly configuration instead of python code. So it's just another way
of writing the plugin you already have.

> I wanted to add another field called "queryLanguage" which is essentially a
> list of options.  So, I can have something like
>
> queryLanguage: ["sql", "sparql"].
>
> This is what drove me to ask the question.  Do I use this plugin in
> conjunction with ckanext-scheming?

No, for scheming you would need to change the way your plugin is
written (and use the latest ckan master version)

The reason I wrote fluent as a separate extension, and plan to write
the repeating extension the same way is so that people can reuse those
new field types even in plugins that *don't* use scheming. You just
need to add the validators to your schema, update your form to submit
data the right way, and update your display template to display it the
way you want.

When I have something usable for this purpose I'll reply to this
thread. For now the simplest thing to do for the list field you want
to add is to store it as a delimited string. It's possible to convert
from that to the new field type transparently with a show validator if
you choose to switch later.

Ian



More information about the ckan-dev mailing list