ckanext-scheming
ckanext-scheming copied to clipboard
Support list of dicts
I want to accept arbitrary dicts for a field that i defined in a scheme. It seems that CKAN tries to apply some kind of sub-schema if it encounters a list of dicts. Is it possible to define such sub-schemas with this extension? And if the fields are not known, all the data is put into the key "__junk" as a flattened dict.
What I ended up doing is writing my own validator that gets the values out of the __junk, but I'm pretty sure this is a bad solution (see here for details: https://github.com/ogdch/ckanext-switzerland/blob/421de6c546462f0ac5764f93064d68d285addda2/ckanext/switzerland/validators.py#L39-L62).
Any ideas how to handle this?
ckan's validation lets you define these sub-schemas by specifying a dict of validators for all the sub-fields instead of a list of validators. scheming only supports the latter at the moment, but you could subclass the plugin to change that behaviour, or modify scheming to allow a dict in the validators sections to be passed through.
You'll also have to come up with a clever way to store these fields as extras, possibly in __before and __after validators.
I'm interested to see if you find a nice solution for this.
@metaodi does your solution only work from the API or can you accept data from a form too?
@wardi I have no GUI for the list of dicts, so I can't really test this right now. I currently still use my "ugly" solution, but I'll keep you posted if there is any progress in that regard.
Here is a shot at solving a cheapo version of this problem (objects in list contain only primitives, good enough for us). https://ckan4rdm.wordpress.com/2016/03/04/list-of-authors/#comment-3
@hvwaldow very cool!
I was planning to merge relatively trivial ckanext-repeating code into ckanext-scheming. Are there any changes you'd like to see to either that would help ckanext-composite do its thing?
Credits for this go to @espona.
Hard to tell. Actually composite
copies quite a bit of repeating
. I am using also other additions on top of scheming and repeating. Need to re-factor before I can come with with good suggestions. That is not happening now.
Generally I think scheming makes people write a lot of custom form_snippets, display_snippets and validators that are hidden away in obscure extensions (talking about my stuff now). Some sort of curated ckanext-scheming-extras
to collect those would be helpful.
Sure, or if they're generally useful and easy enough to customize they can be added to ckanext-scheming itself. That makes it easier to fix them when scheming needs to be refactored.
Sort of staging area: Dump code for custom fields there that works for you. Others can pillage there. Once patterns / heavy usage emerges, someone hopefully does a high-quality version to be pulled into ckanext-scheming
.
@hvwaldow if you're willing to maintain it I'm happy to create the repo for you
@wardi So I nicely talked me into some more work, yes? Generally positive. I'll try to start such a thing containing my little additions. I'll tell you when there is something to look at.