Skip to content

Commit

Permalink
[#1795] remove thing_type from plugin_validate and validate plugin me…
Browse files Browse the repository at this point in the history
…thods
  • Loading branch information
wardi committed Oct 23, 2014
1 parent b5163de commit 7b10857
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 18 deletions.
5 changes: 2 additions & 3 deletions ckan/lib/plugins.py
Expand Up @@ -170,14 +170,13 @@ def register_group_plugins(map):
_default_group_plugin = DefaultGroupForm()


def plugin_validate(plugin, context, data_dict, schema, action, thing_type):
def plugin_validate(plugin, context, data_dict, schema, action):
"""
Backwards compatibility with 2.x dataset group and org plugins:
return a default validate method if one has not been provided.
"""
if hasattr(plugin, 'validate'):
result = plugin.validate(
context, data_dict, schema, action, thing_type)
result = plugin.validate(context, data_dict, schema, action)
if result is not None:
return result

Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/search/index.py
Expand Up @@ -113,7 +113,7 @@ def index_package(self, pkg_dict, defer_commit=False):
schema = package_plugin.show_package_schema()
validated_pkg_dict, errors = lib_plugins.plugin_validate(
package_plugin, {'model': model, 'session': model.Session},
pkg_dict, schema, 'package_show', pkg_dict.get('type'))
pkg_dict, schema, 'package_show')
pkg_dict['validated_data_dict'] = json.dumps(validated_pkg_dict,
cls=ckan.lib.navl.dictization_functions.MissingNullEncoder)

Expand Down
5 changes: 2 additions & 3 deletions ckan/logic/action/create.py
Expand Up @@ -151,8 +151,7 @@ def package_create(context, data_dict):
package_plugin.check_data_dict(data_dict)

data, errors = lib_plugins.plugin_validate(
package_plugin, context, data_dict, schema,
'package_create', package_type)
package_plugin, context, data_dict, schema, 'package_create')
log.debug('package_create validate_errs=%r user=%s package=%s data=%r',
errors, context.get('user'),
data.get('name'), data_dict)
Expand Down Expand Up @@ -596,7 +595,7 @@ def _group_or_org_create(context, data_dict, is_org=False):

data, errors = lib_plugins.plugin_validate(
group_plugin, context, data_dict, schema,
'organization_create' if is_org else 'group_create', group_type)
'organization_create' if is_org else 'group_create')
log.debug('group_create validate_errs=%r user=%s group=%s data_dict=%r',
errors, context.get('user'), data_dict.get('name'), data_dict)

Expand Down
4 changes: 2 additions & 2 deletions ckan/logic/action/get.py
Expand Up @@ -957,7 +957,7 @@ def package_show(context, data_dict):
if schema and context.get('validate', True):
package_dict, errors = lib_plugins.plugin_validate(
package_plugin, context, package_dict, schema,
'package_show', package_dict['type'])
'package_show')

for item in plugins.PluginImplementations(plugins.IPackageController):
item.after_show(context, package_dict)
Expand Down Expand Up @@ -1159,7 +1159,7 @@ def _group_or_org_show(context, data_dict, is_org=False):
schema = logic.schema.default_show_group_schema()
group_dict, errors = lib_plugins.plugin_validate(
group_plugin, context, group_dict, schema,
'organization_show' if is_org else 'group_show', group_dict['type'])
'organization_show' if is_org else 'group_show')
return group_dict


Expand Down
5 changes: 2 additions & 3 deletions ckan/logic/action/update.py
Expand Up @@ -392,8 +392,7 @@ def package_update(context, data_dict):
package_plugin.check_data_dict(data_dict)

data, errors = lib_plugins.plugin_validate(
package_plugin, context, data_dict, schema,
'package_update', pkg.type)
package_plugin, context, data_dict, schema, 'package_update')
log.debug('package_update validate_errs=%r user=%s package=%s data=%r',
errors, context.get('user'),
context.get('package').name if context.get('package') else '',
Expand Down Expand Up @@ -597,7 +596,7 @@ def _group_or_org_update(context, data_dict, is_org=False):

data, errors = lib_plugins.plugin_validate(
group_plugin, context, data_dict, schema,
'organization_update' if is_org else 'group_update', group.type)
'organization_update' if is_org else 'group_update')
log.debug('group_update validate_errs=%r user=%s group=%s data_dict=%r',
errors, context.get('user'),
context.get('group').name if context.get('group') else '',
Expand Down
8 changes: 2 additions & 6 deletions ckan/plugins/interfaces.py
Expand Up @@ -957,7 +957,7 @@ def resource_form(self):
:rtype: string
'''

def validate(self, context, data_dict, schema, action, dataset_type):
def validate(self, context, data_dict, schema, action):
"""Customize validation of datasets.
When this method is implemented it is used to perform all validation
Expand All @@ -982,8 +982,6 @@ def validate(self, context, data_dict, schema, action, dataset_type):
:param action: ``'package_show'``, ``'package_create'`` or
``'package_update'``
:type action: string
:param dataset_type: the type of the dataset
:type dataset_type: 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
Expand Down Expand Up @@ -1110,7 +1108,7 @@ def setup_template_variables(self, context, data_dict):
Add variables to c just prior to the template being rendered.
"""

def validate(self, context, data_dict, schema, action, group_type):
def validate(self, context, data_dict, schema, action):
"""Customize validation of groups.
When this method is implemented it is used to perform all validation
Expand All @@ -1136,8 +1134,6 @@ def validate(self, context, data_dict, schema, action, group_type):
``'group_update'``, ``'organization_show'``,
``'organization_create'`` or ``'organization_update'``
:type action: string
:param group_type: the type of the group
:type group_type: 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
Expand Down

0 comments on commit 7b10857

Please sign in to comment.