[ckan-dev] Custom Validator Question
Pedro G Silva
pedro.gracio at deimos.com.pt
Mon Jan 4 16:05:40 UTC 2016
Hi
Im trying to construct my own validator using
http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html#custom-validators
trying to do no. 5. a callable object taking two parameters
validator(value, context). When trying to use it I get an error:
UnknownValidator: Validator `cloud_coverage_val` does not exist
Any ideas why? I also tried option no1 wuth no success.
I have the following code:
import ckan.plugins as p
import ckan.plugins.toolkit as tk
from ckan.plugins.toolkit import Invalid
def cloud_coverage_val(value, context):
if not value.isdigit():
raise Invalid("Invalid cloud coverage value, must be number
between 0.0 and 100.0")
return float(value)
class ExtrafieldsPlugin(p.SingletonPlugin, tk.DefaultDatasetForm):
p.implements(p.IDatasetForm)
#########
p.implements(p.IConfigurer)
# IConfigurer
def update_config(self, config_):
tk.add_template_directory(config_, 'templates')
tk.add_public_directory(config_, 'public')
tk.add_resource('fanstatic', 'extrafields')
*[OMITTED CODE]*
def show_package_schema(self):
schema = super(ExtrafieldsPlugin, self).show_package_schema()
# Add our custom_text field to the dataset schema.
# schema.update({
# 'CloudCover': [tk.get_converter('convert_from_extras'),
# tk.get_validator('ignore_missing')]
# })
schema.update({
'cloud_cover' : [ tk.get_converter('convert_from_extras'),
tk.get_validator('ignore_missing'),
tk.get_validator('cloud_coverage_val')]
})
schema['resources'].update({
'cloud_cover_resource' : [ tk.get_validator('ignore_missing') ]
})
return schema
--
[image: DEIMOS Engenharia, SA] <http://www.deimos.pt>
*Pedro Gracio Silva*
Aerospace Systems / Production Center
*Av. D. Joao II, Lt 1.17.01, 10 • 1998-023 Lisboa, Portugal*
Ph: +351 21 893 3020 • Fax: +351 21 896 9099
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20160104/423eb557/attachment-0002.html>
More information about the ckan-dev
mailing list