So you could customize the CKAN web front end, for different types of datasets. In this tutorial we will be defining our plugin as the fallback plugin. This plugin is used if no other IDatasetForm plugin is found that handles that dataset type. The IDatasetForm also has other additional functions that allow you to provide a custom template to be rendered for the CKAN frontend, but we will not be using them for this tutorial. Here we have a validator to tell CKAN to not raise a validation error if the value is missing and a converter to convert the value to and save as an extra.
This time, instead of converting to an extras field, we want our field to be converted from an extras field. Each dataset has a field containing its type. Plugins can register to handle specific types of dataset and ignore others. Since our plugin is not for any specific type of dataset and we want our plugin to be the default handler, we update the plugin code to contain the following: Return True to register this plugin as the default handler for package types not handled by any other IDatasetForm plugin.
This plugin doesn't handle any special package types, it just registers itself as the default above. Add the following code to your plugin. We need to override a few templates in order to get our custom field rendered. New in version 2. Starting from CKAN 2. There is a bit of duplication that we could remove. Replace the two functions with: Any of the following objects may be used as validators as part of a custom dataset, group or organization schema.
On a web form this validation error would appear next to the field to which the validator was applied. This form is useful for converting data as well, because the return value will replace the field value passed: All fields and errors in a flattened form are passed to the validator. The return value from this function is ignored. For example 'notes', for the dataset notes field or 'resources', 0, 'url' for the url of the first resource of the dataset.
We will need to create our vocabulary first. Add a function to your plugin. Now we have a way of retrieving our tag vocabularies and creating them if they do not exist.
We just need our plugin to call this code. A converter is required to convert the field in to our tag in a similar way to how we converted our field to extras earlier. We include this line so that vocab tags are not shown mixed with normal free tags.
We modify this dict in a similar way to the dataset schema. It might be better to test that custom templates returned by these methods are actually used, not just that the methods get called. Save and reload your development server CKAN will take any additional keys from the resource schema and save them the its extras field. If you reload your development server you should be able to see these two additional sorting options on the dataset search page.
The SOLR sort ordering can define arbitrary functions for custom sorting, but this is beyond the scope of this tutorial for further details see http: