From ad07692ac6c1a8c23e4a5bba54bb9defe1a89621 Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 28 Mar 2013 15:37:21 +0000 Subject: [PATCH] [#716] Allow to pass the schema as part of the context 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. --- ckan/logic/action/create.py | 5 ++++- ckan/logic/action/get.py | 5 ++++- ckan/logic/action/update.py | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ckan/logic/action/create.py b/ckan/logic/action/create.py index df259500790..2dfc02189a0 100644 --- a/ckan/logic/action/create.py +++ b/ckan/logic/action/create.py @@ -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) diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index cdeda998d1e..b9d9bda56c7 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -731,7 +731,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) diff --git a/ckan/logic/action/update.py b/ckan/logic/action/update.py index d6b969bc923..9f9e18dc834 100644 --- a/ckan/logic/action/update.py +++ b/ckan/logic/action/update.py @@ -235,7 +235,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