def conditional_not_empty(key, data, errors, context): if is_sysadmin(context['user']) and data[('validation_override',)]: ignore_missing(key, data, errors, context) elif data[('catalog_type',)] != ctype: ignore_missing(key, data, errors, context) else: not_empty(key, data, errors, context)
def conditional_not_empty(key, data, errors, context): if is_sysadmin(context['user']) and data[('validation_override', )]: ignore_missing(key, data, errors, context) elif data[('catalog_type', )] != ctype: ignore_missing(key, data, errors, context) else: not_empty(key, data, errors, context)
def check_resource_status(key, data, errors, context): ''' This method checks the value of fields that are depended on resource_status. ''' #Get the current value of resource status resource_status_key = (_('resource_status'), ) if resource_status_key in data: resource_status = data[resource_status_key] #Check if the field is empty when the value of resource_status is obsolete and when the key is replacement_record). if (key[0] == _('replacement_record')): if (resource_status and resource_status == _('obsolete') and (not data[key])): errors[key].append(_('The replacement record cannot be empty.')) else: ignore_missing(key, data, errors, context) return #Check if the field is empty when the value of resource_status is historicalArchive if (resource_status and resource_status == _('historicalArchive') and (not data[key])): if (key[0] == _('retention_expiry_date') or key[0] == _('source_data_path')): errors[key].append(_('Missing value. This field cannot be empty.')) else: ignore_missing(key, data, errors, context)
def not_empty_allow_override(key, data, errors, context): """ Not empty, but allow sysadmins to override the validation error by setting a value in data[(validation_override,)]. """ if is_sysadmin(context['user']) and data.get(('validation_override',)): ignore_missing(key, data, errors, context) else: not_empty(key, data, errors, context)
def not_empty_allow_override(key, data, errors, context): """ Not empty, but allow sysadmins to override the validation error by setting a value in data[(validation_override,)]. """ if is_sysadmin(context['user']) and data.get(('validation_override', )): ignore_missing(key, data, errors, context) else: not_empty(key, data, errors, context)
def _not_empty_if_ready_to_publish(key, data, errors, context): """ Not empty, but allow sysadmins to override the validation error by setting a value in data[(validation_override,)]. """ v = data.get(('ready_to_publish',), True) if v is missing or v: not_empty(key, data, errors, context) else: ignore_missing(key, data, errors, context)
def check_branch(key, data, errors, context): ignore_missing(key, data, errors, context) return from ckanext.bcgov.util.util import get_organization_branches org_key = ('org',) org_id = None if org_key in data: org_id = data[org_key] #Check if the organization has any branches branches = get_organization_branches(org_id) if len(branches) > 0 : value = data.get(key) if not value or value is missing: errors[key].append(_('Missing value')) raise StopOnError
def check_branch(key, data, errors, context): ignore_missing(key, data, errors, context) return from ckanext.bcgov.util.util import get_organization_branches org_key = ('org', ) org_id = None if org_key in data: org_id = data[org_key] #Check if the organization has any branches branches = get_organization_branches(org_id) if len(branches) > 0: value = data.get(key) if not value or value is missing: errors[key].append(_('Missing value')) raise StopOnError
def check_resource_status(key, data, errors, context): ''' This method checks the value of fields that are depended on resource_status. ''' #Get the current value of resource status resource_status_key = (_('resource_status'),) if resource_status_key in data : resource_status = data[resource_status_key] #Check if the field is empty when the value of resource_status is obsolete and when the key is replacement_record). if (key[0] == _('replacement_record')): if (resource_status and resource_status == _('obsolete') and (not data[key])) : errors[key].append(_('The replacement record cannot be empty.')) else: ignore_missing(key, data, errors, context) return #Check if the field is empty when the value of resource_status is historicalArchive if (resource_status and resource_status == _('historicalArchive') and (not data[key])): if (key[0] == _('retention_expiry_date') or key[0] == _('source_data_path')): errors[key].append(_('Missing value. This field cannot be empty.')) else: ignore_missing(key, data, errors, context)
def check_resource_status(key, data, errors, context): """ This method checks the value of fields that are depended on resource_status. """ # Get the current value of resource status resource_status_key = (_("resource_status"),) if resource_status_key in data: resource_status = data[resource_status_key] # Check if the field is empty when the value of resource_status is obsolete and when the key is replacement_record). if key[0] == _("replacement_record"): if resource_status and resource_status == _("obsolete") and (not data[key]): errors[key].append(_("The replacement record cannot be empty.")) else: ignore_missing(key, data, errors, context) return # Check if the field is empty when the value of resource_status is historicalArchive if resource_status and resource_status == _("historicalArchive") and (not data[key]): if key[0] == _("retention_expiry_date") or key[0] == _("source_data_path"): errors[key].append(_("Missing value. This field cannot be empty.")) else: ignore_missing(key, data, errors, context)
def ignore_missing_only_sysadmin(key, data, errors, context): """ Ignore missing field *only* if the user is a sysadmin. """ if is_sysadmin(context['user']): return ignore_missing(key, data, errors, context)
def call_validator(*args, **kwargs): return validators.ignore_missing(*args, **kwargs)
def conditional_not_empty(key, data, errors, context): if data.get(('catalog_type',)) != ctype_key: ignore_missing(key, data, errors, context) else: _not_empty_if_ready_to_publish(key, data, errors, context)