diff --git a/MANIFEST.in b/MANIFEST.in index cbb4ca17..c826131c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ include README.rst include LICENSE include requirements.txt -recursive-include ckanext/validation *.html *.json *.js *.less *.css *.mo \ No newline at end of file +recursive-include ckanext/validation *.html *.json *.js *.less *.css *.mo diff --git a/ckanext/validation/logic.py b/ckanext/validation/logic.py index 213e4648..8bc6d31b 100644 --- a/ckanext/validation/logic.py +++ b/ckanext/validation/logic.py @@ -24,6 +24,8 @@ log = logging.getLogger(__name__) +ckan_2_10 = t.check_ckan_version(min_version="2.10") + def enqueue_job(*args, **kwargs): try: @@ -448,9 +450,14 @@ def resource_create(up_func, context, data_dict): {'id': package_id}) t.check_access('resource_create', context, data_dict) - - for plugin in plugins.PluginImplementations(plugins.IResourceController): - plugin.before_create(context, data_dict) + + # Check if CKAN version is min 2.10 + if ckan_2_10: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.before_resource_create(context, data_dict) + else: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.before_create(context, data_dict) if 'resources' not in pkg_dict: pkg_dict['resources'] = [] @@ -519,9 +526,13 @@ def resource_create(up_func, context, data_dict): {'resource': resource, 'package': updated_pkg_dict }) - - for plugin in plugins.PluginImplementations(plugins.IResourceController): - plugin.after_create(context, resource) + + if ckan_2_10: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.after_resource_create(context, resource) + else: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.after_create(context, resource) return resource @@ -575,9 +586,13 @@ def resource_update(up_func, context, data_dict): if ('datastore_active' in resource.extras and 'datastore_active' not in data_dict): data_dict['datastore_active'] = resource.extras['datastore_active'] - - for plugin in plugins.PluginImplementations(plugins.IResourceController): - plugin.before_update(context, pkg_dict['resources'][n], data_dict) + + if ckan_2_10: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.before_resource_update(context, pkg_dict['resources'][n], data_dict) + else: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.before_update(context, pkg_dict['resources'][n], data_dict) upload = uploader.get_resource_uploader(data_dict) @@ -636,8 +651,12 @@ def resource_update(up_func, context, data_dict): {'package': updated_pkg_dict, 'resource': resource}) - for plugin in plugins.PluginImplementations(plugins.IResourceController): - plugin.after_update(context, resource) + if ckan_2_10: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.after_resource_update(context, resource) + else: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.after_update(context, resource) return resource diff --git a/ckanext/validation/plugin/__init__.py b/ckanext/validation/plugin/__init__.py index d648709e..a3bc978e 100644 --- a/ckanext/validation/plugin/__init__.py +++ b/ckanext/validation/plugin/__init__.py @@ -41,6 +41,8 @@ ALLOWED_UPLOAD_TYPES = (cgi.FieldStorage, FlaskFileStorage) log = logging.getLogger(__name__) +ckan_2_10 = t.check_ckan_version(min_version="2.10") + class ValidationPlugin(p.SingletonPlugin): p.implements(p.IConfigurer) @@ -153,12 +155,15 @@ def _process_schema_fields(self, data_dict): return data_dict + def before_resource_create(self, context, data_dict): + + context["_resource_create_call"] = True + return self._process_schema_fields(data_dict) + def before_create(self, context, data_dict): - is_dataset = self._data_dict_is_dataset(data_dict) - if not is_dataset: - context["_resource_create_call"] = True - return self._process_schema_fields(data_dict) + if not self._data_dict_is_dataset(data_dict): + return self.before_resource_create(context, data_dict) def after_create(self, context, data_dict): @@ -302,6 +307,16 @@ def after_update(self, context, data_dict): del self.resources_to_validate[resource_id] _run_async_validation(resource_id) + + def after_dataset_create(self, context, data_dict): + self.after_create(context, data_dict) + + def before_resource_update(self, context, current_resource, updated_resource): + self.before_update(context, current_resource, updated_resource) + + def after_dataset_update(self, context, data_dict): + self.after_update(context, data_dict) + # IPackageController