Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CKAN 2.10 compatability #98

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include README.rst
include LICENSE
include requirements.txt
recursive-include ckanext/validation *.html *.json *.js *.less *.css *.mo
recursive-include ckanext/validation *.html *.json *.js *.less *.css *.mo
41 changes: 30 additions & 11 deletions ckanext/validation/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'] = []
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
23 changes: 19 additions & 4 deletions ckanext/validation/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
blagojabozinovski marked this conversation as resolved.
Show resolved Hide resolved

def after_create(self, context, data_dict):

Expand Down Expand Up @@ -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

Expand Down
Loading