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

Use IDomainObjectModification Implementation #69

Merged
22 changes: 18 additions & 4 deletions ckanext/xloader/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from ckan import plugins
from ckan.plugins import toolkit

from ckan.model.domain_object import DomainObjectOperation
from ckan.model.resource import Resource

from . import action, auth, helpers as xloader_helpers, utils
from ckanext.xloader.utils import XLoaderFormats

Expand All @@ -23,7 +26,7 @@ def config_declarations(cls):
class xloaderPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IConfigurable)
plugins.implements(plugins.IResourceUrlChange)
plugins.implements(plugins.IDomainObjectModification)
plugins.implements(plugins.IActions)
plugins.implements(plugins.IAuthFunctions)
plugins.implements(plugins.ITemplateHelpers)
Expand Down Expand Up @@ -64,16 +67,27 @@ def configure(self, config_):
)
)

# IResourceUrlChange
# IDomainObjectModification

def notify(self, resource):
def notify(self, entity, operation):
# type: (ckan.model.Package|ckan.model.Resource, DomainObjectOperation) -> None
"""
Runs before_commit to database for Packages and Resources.
We only want to check for changed Resources for this.
We want to check if values have changed, namely the url.
See: ckan/model/modification.py.DomainObjectModificationExtension
"""
if operation != DomainObjectOperation.changed \
or not isinstance(entity, Resource) \
or not getattr(entity, 'url_changed', False):
return
context = {
"ignore_auth": True,
}
resource_dict = toolkit.get_action("resource_show")(
context,
{
"id": resource.id,
"id": entity.id,
},
)
self._submit_to_xloader(resource_dict)
Expand Down