Skip to content

Commit

Permalink
Merge remote-tracking branch 'keitaroinc/ckan-2.10' into chore_cicd_toml
Browse files Browse the repository at this point in the history
  • Loading branch information
duttonw committed Dec 9, 2024
2 parents 12fd8e8 + 15f47ac commit 2c97caf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
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 @@ -25,6 +25,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 @@ -433,9 +435,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 @@ -504,9 +511,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 @@ -560,9 +571,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 @@ -621,8 +636,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)

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)


if _should_remove_unsupported_resource_validation_reports(data_dict):
p.toolkit.enqueue_job(fn=_remove_unsupported_resource_validation_reports, args=[resource_id])
Expand Down

0 comments on commit 2c97caf

Please sign in to comment.