From d2720fcf8ec35fb9082a4e48bb12759133dfa903 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 31 Jan 2024 16:37:10 +0000 Subject: [PATCH] fix(syntax): flake8; - Syntax fixes from flake8. --- ckanext/xloader/plugin.py | 17 +++++++++++------ ckanext/xloader/utils.py | 11 ++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ckanext/xloader/plugin.py b/ckanext/xloader/plugin.py index edaa34bd..19e88b9b 100644 --- a/ckanext/xloader/plugin.py +++ b/ckanext/xloader/plugin.py @@ -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 @@ -99,7 +100,7 @@ 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. @@ -107,7 +108,7 @@ def notify(self, entity, operation): 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 @@ -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 @@ -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): diff --git a/ckanext/xloader/utils.py b/ckanext/xloader/utils.py index 3bb20a98..7a0fdb87 100644 --- a/ckanext/xloader/utils.py +++ b/ckanext/xloader/utils.py @@ -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, } @@ -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 ) @@ -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 @@ -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