Skip to content

Commit d2720fc

Browse files
committed
fix(syntax): flake8;
- Syntax fixes from flake8.
1 parent 25ea76e commit d2720fc

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

ckanext/xloader/plugin.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from ckan.model.domain_object import DomainObjectOperation
99
from ckan.model.resource import Resource
10+
from ckan.model.package import Package
1011

1112
from . import action, auth, helpers as xloader_helpers, utils
1213

@@ -99,15 +100,15 @@ def configure(self, config_):
99100
# IDomainObjectModification
100101

101102
def notify(self, entity, operation):
102-
# type: (ckan.model.Package|ckan.model.Resource, DomainObjectOperation) -> None
103+
# type: (Package|Resource, DomainObjectOperation) -> None
103104
"""
104105
Runs before_commit to database for Packages and Resources.
105106
We only want to check for changed Resources for this.
106107
We want to check if values have changed, namely the url.
107108
See: ckan/model/modification.py.DomainObjectModificationExtension
108109
"""
109110
if operation != DomainObjectOperation.changed \
110-
or not isinstance(entity, Resource):
111+
or not isinstance(entity, Resource):
111112
return
112113

113114
# If the resource requires validation, stop here if validation
@@ -116,11 +117,13 @@ def notify(self, entity, operation):
116117
# be called again. However, url_changed will not be in the entity
117118
# once Validation does the patch.
118119
if utils.is_validation_plugin_loaded() and \
119-
toolkit.asbool(toolkit.config.get('ckanext.xloader.requires_validation')):
120+
toolkit.asbool(toolkit.config.get('ckanext.xloader.requires_validation')):
121+
120122
if entity.__dict__.get('extras', {}).get('validation_status', None) != 'success':
121123
log.debug("Skipping xloading resource %s because the "
122124
"resource did not pass validation yet.", entity.id)
123125
return
126+
124127
elif not getattr(entity, 'url_changed', False):
125128
return
126129

@@ -139,11 +142,13 @@ def notify(self, entity, operation):
139142

140143
def after_resource_create(self, context, resource_dict):
141144
if utils.is_validation_plugin_loaded() and \
142-
toolkit.asbool(toolkit.config.get('ckanext.xloader.requires_validation')) and \
143-
resource_dict.get('validation_status', None) != 'success':
145+
toolkit.asbool(toolkit.config.get('ckanext.xloader.requires_validation')) and \
146+
resource_dict.get('validation_status', None) != 'success':
147+
144148
log.debug("Skipping xloading resource %s because the "
145-
"resource did not pass validation yet.", resource_dict.get('id'))
149+
"resource did not pass validation yet.", resource_dict.get('id'))
146150
return
151+
147152
self._submit_to_xloader(resource_dict)
148153

149154
def before_resource_show(self, resource_dict):

ckanext/xloader/utils.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
from decimal import Decimal
1010

1111
import ckan.plugins as p
12-
from ckan.plugins.toolkit import config, h, _
12+
from ckan.plugins.toolkit import h, _
1313

1414

1515
def resource_data(id, resource_id, rows=None):
1616

1717
if p.toolkit.request.method == "POST":
1818
if is_validation_plugin_loaded() and \
19-
p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.requires_validation')):
19+
p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.requires_validation')):
20+
2021
context = {
2122
"ignore_auth": True,
2223
}
@@ -28,7 +29,7 @@ def resource_data(id, resource_id, rows=None):
2829
)
2930
if resource_dict.get('validation_status', None) != 'success':
3031
h.flash_error(_("Cannot upload resource %s to the DataStore "
31-
"because the resource did not pass validation yet.") % resource_id)
32+
"because the resource did not pass validation yet.") % resource_id)
3233
return p.toolkit.redirect_to(
3334
"xloader.resource_data", id=id, resource_id=resource_id
3435
)
@@ -187,7 +188,7 @@ def type_guess(rows, types=TYPES, strict=False):
187188
at_least_one_value = []
188189
for ri, row in enumerate(rows):
189190
diff = len(row) - len(guesses)
190-
for _ in range(diff):
191+
for _i in range(diff):
191192
typesdict = {}
192193
for type in types:
193194
typesdict[type] = 0
@@ -213,7 +214,7 @@ def type_guess(rows, types=TYPES, strict=False):
213214
else:
214215
for i, row in enumerate(rows):
215216
diff = len(row) - len(guesses)
216-
for _ in range(diff):
217+
for _i in range(diff):
217218
guesses.append(defaultdict(int))
218219
for i, cell in enumerate(row):
219220
# add string guess so that we have at least one guess

0 commit comments

Comments
 (0)