Skip to content

Commit

Permalink
Merge pull request #16 from keitaroinc/code-cleanup
Browse files Browse the repository at this point in the history
Add CKAN 2.10 compatable fucntions in plugin
  • Loading branch information
blagojabozinovski authored Apr 1, 2024
2 parents 0eb829a + 267da30 commit 02eeacf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
image: openknowledge/ckan-dev:${{ matrix.ckan-version }}
services:
solr:
image: ckan/ckan-solr-dev:${{ matrix.ckan-version }}
image: ckan/ckan-solr:2.9-solr9
postgres:
image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }}
env:
Expand Down
27 changes: 24 additions & 3 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,19 @@ def _process_schema_fields(self, data_dict):

return data_dict

def before_create(self, context, data_dict):
if 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 self._process_schema_fields(data_dict)

else:
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)

def after_create(self, context, data_dict):

Expand Down Expand Up @@ -302,6 +311,18 @@ def after_update(self, context, data_dict):
del self.resources_to_validate[resource_id]

_run_async_validation(resource_id)

if ckan_2_10:

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

0 comments on commit 02eeacf

Please sign in to comment.