[ckan-dev] Adding custom metadata in stage 3 (IDatasetForm)

Hendrik Bunke bunke.hendrik at gmail.com
Wed May 8 14:07:34 UTC 2013


--On 2013-05-08 13:33, Toby Dacre wrote:
> On 8 May 2013 13:17, Ian Ward <ian at excess.org> wrote:
> >
> > On May 8, 2013 8:06 AM, "Hendrik Bunke" <bunke.hendrik at gmail.com> wrote:
> >>
> >> Sean, thanks for answering. Yes, I've seen the example plugin and
> >> actually used it as a starter. The point is, that the example
> >> also does not store metadata from stage 3, only from stage 1. So,
> >> either there's something me and the example are missing, or
> >> there's some general problem. I suppose the validation goes wrong
> >> somehow here, since the converter seems to do well, as far as I
> >> can see with debugging.
> >>
> >
> > I know you can't have required fields on the 3rd page. Is that the problem?
> >
> 
> Or more precisely - all required fields must be on the first page

Yes, I know that (although perhaps it should be mentioned
somewhere in the docs), but that's not the problem. Problem is,
that no custom field at all gets stored into 'extras'.

In the meantime I've done some more debugging and finally found the
reason. If on stage 1 the field get's no value, it is stored as
'MissingObject'. This value does not get overwritten in stage 3,
even if the user gives a new (real) value. Depending on the
validator ('ignore_missing' in my case) the key is deleted in the
end.

As a simple test for this I've written my own validator and added
it to ckan/lib/navl/validators.py:

def empty_value(key, data, errors, context):
    value = data.get(key)
    if not value or value is missing:
        data[key] = ''

This works, at least it does overwrite the 'Missing' object and
the field is finally stored in 'extras'. But unfortunately later
on it also overwrites the input value of stage 3.

Is there really no way to add custom optional metadata in stage
3?

best
hendrik

-- 
Dr. Hendrik Bunke
http://gplus.to/hbunke
http://twitter.com/hbunke
http://www.hbxt.org




More information about the ckan-dev mailing list