Skip to content

Commit

Permalink
fix(syntax): flake8;
Browse files Browse the repository at this point in the history
- Syntax fixes from flake8.
  • Loading branch information
JVickery-TBS committed Jan 31, 2024
1 parent 25ea76e commit d2720fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
17 changes: 11 additions & 6 deletions ckanext/xloader/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

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

Expand Down Expand Up @@ -99,15 +100,15 @@ def configure(self, config_):
# IDomainObjectModification

def notify(self, entity, operation):
# type: (ckan.model.Package|ckan.model.Resource, DomainObjectOperation) -> None
# type: (Package|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 isinstance(entity, Resource):
return

# If the resource requires validation, stop here if validation
Expand All @@ -116,11 +117,13 @@ def notify(self, entity, operation):
# be called again. However, url_changed will not be in the entity
# once Validation does the patch.
if utils.is_validation_plugin_loaded() and \
toolkit.asbool(toolkit.config.get('ckanext.xloader.requires_validation')):
toolkit.asbool(toolkit.config.get('ckanext.xloader.requires_validation')):

if entity.__dict__.get('extras', {}).get('validation_status', None) != 'success':
log.debug("Skipping xloading resource %s because the "
"resource did not pass validation yet.", entity.id)
return

elif not getattr(entity, 'url_changed', False):
return

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

def after_resource_create(self, context, resource_dict):
if utils.is_validation_plugin_loaded() and \
toolkit.asbool(toolkit.config.get('ckanext.xloader.requires_validation')) and \
resource_dict.get('validation_status', None) != 'success':
toolkit.asbool(toolkit.config.get('ckanext.xloader.requires_validation')) and \
resource_dict.get('validation_status', None) != 'success':

log.debug("Skipping xloading resource %s because the "
"resource did not pass validation yet.", resource_dict.get('id'))
"resource did not pass validation yet.", resource_dict.get('id'))
return

self._submit_to_xloader(resource_dict)

def before_resource_show(self, resource_dict):
Expand Down
11 changes: 6 additions & 5 deletions ckanext/xloader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
from decimal import Decimal

import ckan.plugins as p
from ckan.plugins.toolkit import config, h, _
from ckan.plugins.toolkit import h, _


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

if p.toolkit.request.method == "POST":
if is_validation_plugin_loaded() and \
p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.requires_validation')):
p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.requires_validation')):

context = {
"ignore_auth": True,
}
Expand All @@ -28,7 +29,7 @@ def resource_data(id, resource_id, rows=None):
)
if resource_dict.get('validation_status', None) != 'success':
h.flash_error(_("Cannot upload resource %s to the DataStore "
"because the resource did not pass validation yet.") % resource_id)
"because the resource did not pass validation yet.") % resource_id)
return p.toolkit.redirect_to(
"xloader.resource_data", id=id, resource_id=resource_id
)
Expand Down Expand Up @@ -187,7 +188,7 @@ def type_guess(rows, types=TYPES, strict=False):
at_least_one_value = []
for ri, row in enumerate(rows):
diff = len(row) - len(guesses)
for _ in range(diff):
for _i in range(diff):
typesdict = {}
for type in types:
typesdict[type] = 0
Expand All @@ -213,7 +214,7 @@ def type_guess(rows, types=TYPES, strict=False):
else:
for i, row in enumerate(rows):
diff = len(row) - len(guesses)
for _ in range(diff):
for _i in range(diff):
guesses.append(defaultdict(int))
for i, cell in enumerate(row):
# add string guess so that we have at least one guess
Expand Down

0 comments on commit d2720fc

Please sign in to comment.