Skip to content

Commit

Permalink
feat(dev): validation support cont.;
Browse files Browse the repository at this point in the history
- Improved logic util method more.
  • Loading branch information
JVickery-TBS committed Feb 2, 2024
1 parent 1ac45ef commit f493dbb
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ckanext/xloader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import ckan.plugins as p
from ckan.plugins.toolkit import config, h, _

from logging import getLogger


log = getLogger(__name__)

# resource.formats accepted by ckanext-xloader. Must be lowercase here.
DEFAULT_FORMATS = [
"csv",
Expand Down Expand Up @@ -52,15 +57,22 @@ def awaiting_validation(res_dict):
Checks ckanext.xloader.validation.enforceDefaultsIfSchemaMissing config
option value. Then checks the Resource's Schema for the `validation_status` field.
"""
if not p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.validation.requiredSoWaitForReport', False)):
# validation.requiredSoWaitForReport is turned off, return right away
return False

try:
# check for one of the main actions from ckanext-validation
# in the case that users extend the Validation plugin class
# and rename the plugin entry-point.
p.toolkit.get_action('resource_validation_show')
is_validation_plugin_loaded = True
except KeyError:
is_validation_plugin_loaded = False

if not is_validation_plugin_loaded or \
not p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.validation.requiredSoWaitForReport', False)):
# the validation plugin is not loaded or the validation.requiredSoWaitForReport is turned off
if not is_validation_plugin_loaded:
# the validation plugin is not loaded but required, log a warning
log.warning('ckanext.xloader.validation.requiredSoWaitForReport requires the ckanext-validation plugin to be activated.')
return False

if p.toolkit.asbool(p.toolkit.config.get('ckanext.xloader.validation.enforceDefaultsIfSchemaMissing', True)):
Expand All @@ -72,6 +84,7 @@ def awaiting_validation(res_dict):
else:
# TODO: check the Resource's schema to see if there is no `validation_status`,
# if there is not, then return False, otherwise check if it is `success` or not.
# default_resource_schema ??
return True

return True
Expand Down

0 comments on commit f493dbb

Please sign in to comment.