Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
duttonw committed Dec 17, 2024
2 parents e4f0a46 + 15f47ac commit 2409a41
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 24 deletions.
41 changes: 30 additions & 11 deletions ckanext/validation/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

log = logging.getLogger(__name__)

ckan_2_10 = t.check_ckan_version(min_version="2.10")


def get_actions():
validators = (
Expand Down Expand Up @@ -408,9 +410,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 @@ -479,9 +486,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 @@ -535,9 +546,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 @@ -596,8 +611,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
53 changes: 40 additions & 13 deletions ckanext/validation/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,23 @@ def get_validators(self):

# CKAN < 2.10
def before_create(self, context, data_dict):
return self.before_resource_create(context, data_dict)

if not self._data_dict_is_dataset(data_dict):
return self.before_resource_create(context, data_dict)


# CKAN >= 2.10
def before_resource_create(self, context, data_dict):

is_dataset = self._data_dict_is_dataset(data_dict)
if not is_dataset:
context["_resource_create_call"] = True
return utils.process_schema_fields(data_dict)
context["_resource_create_call"] = True
return utils.process_schema_fields(data_dict)

# CKAN < 2.10
def after_create(self, context, data_dict):
# if (self._data_dict_is_dataset(data_dict)):
# return self.after_dataset_create(context, data_dict)
# else:
return self.after_resource_create(context, data_dict)
if (self._data_dict_is_dataset(data_dict)):
return self.after_dataset_create(context, data_dict)
else:
return self.after_resource_create(context, data_dict)

# CKAN >= 2.10
def after_resource_create(self, context, data_dict):
Expand Down Expand Up @@ -196,10 +197,10 @@ def before_resource_update(self, context, current_resource, updated_resource):

# CKAN < 2.10
def after_update(self, context, data_dict):
# if (self._data_dict_is_dataset(data_dict)):
# return self.after_dataset_update(context, data_dict)
# else:
return self.after_resource_update(context, data_dict)
if (self._data_dict_is_dataset(data_dict)):
return self.after_dataset_update(context, data_dict)
else:
return self.after_resource_update(context, data_dict)

# CKAN >= 2.10
def after_resource_update(self, context, data_dict):
Expand Down Expand Up @@ -264,6 +265,32 @@ def after_resource_update(self, context, data_dict):

# IPackageController

# CKAN >= 2.10
def after_dataset_create(self, context, data_dict):
log.debug("after_dataset_create");
# This is qld-gov-au implementation, need to see if this is still required
#for resource in data_dict.get(u'resources', []):
# if utils.is_resource_could_be_validated(context, resource):
# utils.validate_resource(context, resource)

# CKAN >= 2.10
def after_dataset_update(self, context, data_dict):
if context.pop('_validation_performed', None) \
or context.pop('_resource_validation', None):
return

for resource in data_dict.get('resources', []):
if resource.pop(u'_do_not_validate', False) \
or resource.pop('_success_validation', False):
continue

if not utils.is_resource_could_be_validated(context, resource):
continue

#This is qld-gov-au implementation, need to see if this is still required
# utils.validate_resource(context, resource)


# CKAN < 2.10
def before_index(self, index_dict):
if (self._data_dict_is_dataset(index_dict)):
Expand Down

0 comments on commit 2409a41

Please sign in to comment.