Skip to content

Commit

Permalink
[#1400] add validate() to IDatasetForm and IGroupForm
Browse files Browse the repository at this point in the history
  • Loading branch information
wardi committed Dec 18, 2013
1 parent bedfdcb commit ca05e99
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions ckan/plugins/interfaces.py
Expand Up @@ -824,6 +824,37 @@ def package_form(self):
'''

def validate(self, data_dict, schema, context, action):
"""Customize validation of datasets.
When this method is implemented it is used to perform all validation
for these datasets. The default implementation calls and returns the
result from ``ckan.plugins.toolkit.navl_validate``.
This is an adavanced interface. Most changes to validation should be
accomplished by customizing the schemas returned from
``show_package_schema()``, ``create_package_schema()``
and ``update_package_schama()``. If you need to have a different
schema depending on the user or value of any field stored in the
dataset, or if you wish to use a different method for validation, then
this method may be used.
:param data_dict: the dataset to be validated
:type data_dict: dictionary
:param schema: a schema, typically from ``show_package_schema()``,
``create_package_schema()`` or ``update_package_schama()``
:type schema: dictionary
:param context: extra information about the request
:type context: dictionary
:param action: ``'package_show'``, ``'package_create'`` or
``'package_update'``
:type action: string
:returns: (data_dict, errors) where data_dict is the possibly-modified
dataset and errors is a dictionary with keys matching data_dict
and lists-of-string-error-messages as values
:rtype: (dictionary, dictionary)
"""


class IGroupForm(Interface):
"""
Expand Down Expand Up @@ -944,6 +975,38 @@ def setup_template_variables(self, context, data_dict):
Add variables to c just prior to the template being rendered.
"""

def validate(self, data_dict, schema, context, action):
"""Customize validation of groups.
When this method is implemented it is used to perform all validation
for these groups. The default implementation calls and returns the
result from ``ckan.plugins.toolkit.navl_validate``.
This is an adavanced interface. Most changes to validation should be
accomplished by customizing the schemas returned from
``form_to_db_schema()`` and ``db_to_form_schema()``
If you need to have a different
schema depending on the user or value of any field stored in the
group, or if you wish to use a different method for validation, then
this method may be used.
:param data_dict: the group to be validated
:type data_dict: dictionary
:param schema: a schema, typically from ``form_to_db_schema()``,
or ``db_to_form_schama()``
:type schema: dictionary
:param context: extra information about the request
:type context: dictionary
:param action: ``'group_show'``, ``'group_create'``,
``'group_update'``, ``'organization_show'``,
``'organization_create'`` or ``'organization_update'``
:type action: string
:returns: (data_dict, errors) where data_dict is the possibly-modified
group and errors is a dictionary with keys matching data_dict
and lists-of-string-error-messages as values
:rtype: (dictionary, dictionary)
"""

##### End of hooks #####

class IFacets(Interface):
Expand Down

0 comments on commit ca05e99

Please sign in to comment.