4
4
5
5
from ckan import plugins
6
6
from ckan .plugins import toolkit
7
- from ckan .model .domain_object import DomainObjectOperation
8
- from ckan .model .resource import Resource
9
7
10
8
from ckan .model .domain_object import DomainObjectOperation
11
9
from ckan .model .resource import Resource
10
+ from ckan .model .package import Package
12
11
13
12
from . import action , auth , helpers as xloader_helpers , utils
14
13
@@ -101,15 +100,15 @@ def configure(self, config_):
101
100
# IDomainObjectModification
102
101
103
102
def notify (self , entity , operation ):
104
- # type: (ckan.model. Package|ckan.model. Resource, DomainObjectOperation) -> None
103
+ # type: (Package|Resource, DomainObjectOperation) -> None
105
104
"""
106
105
Runs before_commit to database for Packages and Resources.
107
106
We only want to check for changed Resources for this.
108
107
We want to check if values have changed, namely the url and the format.
109
108
See: ckan/model/modification.py.DomainObjectModificationExtension
110
109
"""
111
110
if operation != DomainObjectOperation .changed \
112
- or not isinstance (entity , Resource ):
111
+ or not isinstance (entity , Resource ):
113
112
return
114
113
115
114
context = {
@@ -124,7 +123,7 @@ def notify(self, entity, operation):
124
123
125
124
if _should_remove_unsupported_resource_from_datastore (resource_dict ):
126
125
toolkit .enqueue_job (fn = _remove_unsupported_resource_from_datastore , args = [entity .id ])
127
-
126
+
128
127
if not getattr (entity , 'url_changed' , False ):
129
128
# do not submit to xloader if the url has not changed.
130
129
return
@@ -242,9 +241,9 @@ def _should_remove_unsupported_resource_from_datastore(res_dict):
242
241
return False
243
242
return (not XLoaderFormats .is_it_an_xloader_format (res_dict .get ('format' , u'' ))
244
243
and (res_dict .get ('url_type' ) == 'upload'
245
- or not res_dict .get ('url_type' ))
244
+ or not res_dict .get ('url_type' ))
246
245
and (toolkit .asbool (res_dict .get ('datastore_active' , False ))
247
- or toolkit .asbool (res_dict .get ('extras' , {}).get ('datastore_active' , False ))))
246
+ or toolkit .asbool (res_dict .get ('extras' , {}).get ('datastore_active' , False ))))
248
247
249
248
250
249
def _remove_unsupported_resource_from_datastore (resource_id ):
@@ -263,7 +262,7 @@ def _remove_unsupported_resource_from_datastore(resource_id):
263
262
264
263
if _should_remove_unsupported_resource_from_datastore (res ):
265
264
log .info ('Unsupported resource format "%s". Deleting datastore tables for resource %s' ,
266
- res .get (u'format' , u'' ), res ['id' ])
265
+ res .get (u'format' , u'' ), res ['id' ])
267
266
try :
268
267
toolkit .get_action ('datastore_delete' )(context , {
269
268
"resource_id" : res ['id' ],
0 commit comments