Skip to content

Commit

Permalink
[#716] Allow to pass the schema as part of the context
Browse files Browse the repository at this point in the history
In some cases extensions need to tweak the schema used on package
creation or update. For instance harvesters may want to create a package
with a certain id, or relax the default tags schema. There used to be an
option via `form_to_db_schema_options` to provide a custom schema via
the context, but this was removed on the last IDatasetForm refactor.

This adds back the option to pass the schema as part of the context.
  • Loading branch information
amercader committed Apr 17, 2013
1 parent 4ccec75 commit a23e91d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion ckan/logic/action/create.py
Expand Up @@ -109,7 +109,10 @@ def package_create(context, data_dict):

package_type = data_dict.get('type')
package_plugin = lib_plugins.lookup_package_plugin(package_type)
schema = package_plugin.create_package_schema()
if 'schema' in context:
schema = context['schema']
else:
schema = package_plugin.create_package_schema()

_check_access('package_create', context, data_dict)

Expand Down
5 changes: 4 additions & 1 deletion ckan/logic/action/get.py
Expand Up @@ -721,7 +721,10 @@ def package_show(context, data_dict):
item.read(pkg)

package_plugin = lib_plugins.lookup_package_plugin(package_dict['type'])
schema = package_plugin.show_package_schema()
if 'schema' in context:
schema = context['schema']
else:
schema = package_plugin.show_package_schema()

if schema and context.get('validate', True):
package_dict, errors = _validate(package_dict, schema, context=context)
Expand Down
5 changes: 4 additions & 1 deletion ckan/logic/action/update.py
Expand Up @@ -233,7 +233,10 @@ def package_update(context, data_dict):

# get the schema
package_plugin = lib_plugins.lookup_package_plugin(pkg.type)
schema = package_plugin.update_package_schema()
if 'schema' in context:
schema = context['schema']
else:
schema = package_plugin.update_package_schema()

if 'api_version' not in context:
# check_data_dict() is deprecated. If the package_plugin has a
Expand Down

0 comments on commit a23e91d

Please sign in to comment.