diff --git a/README.md b/README.md index 965b6d89..7fe2316b 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,15 @@ Fields you exclude will not be shown to the end user, and will not be accepted when editing or updating this type of dataset. +### `before_validators`, `after_validators` + +```yaml +before_validators: validator_name + +after_validators: validator_name +``` + +Runs validator functions before and after the `dataset_type` package is created/updated. ## Group / Organization Schema Keys @@ -233,6 +242,17 @@ fields: A single `fields` list replaces the `dataset_fields` and `resource_fields` schema properties doin dataset schemas. +### `before_validators`, `after_validators` + +```yaml +before_validators: validator_name + +after_validators: validator_name +``` + +Runs validator functions before and after the `organization_type`/`group_type` group is created/updated. + + ---------------- ## Field Keys diff --git a/ckanext/scheming/plugins.py b/ckanext/scheming/plugins.py index 0980a684..e947d602 100644 --- a/ckanext/scheming/plugins.py +++ b/ckanext/scheming/plugins.py @@ -177,6 +177,16 @@ def validate(self, context, data_dict, schema, action): scheming_schema = self._expanded_schemas[t] scheming_fields = scheming_schema['fields'] + before = scheming_schema.get('before_validators') + after = scheming_schema.get('after_validators') + + if before: + schema['__before'] = validation.validators_from_string( + before, None, scheming_schema) + if after: + schema['__after'] = validation.validators_from_string( + after, None, scheming_schema) + get_validators = ( _field_output_validators_group if action_type == 'show' else _field_validators diff --git a/ckanext/scheming/templates/scheming/group/group_form.html b/ckanext/scheming/templates/scheming/group/group_form.html index b3cf2c9b..60f5ec07 100644 --- a/ckanext/scheming/templates/scheming/group/group_form.html +++ b/ckanext/scheming/templates/scheming/group/group_form.html @@ -10,6 +10,14 @@ {%- endif -%}
+ {% block errors %} + {%- if errors -%} + {%- set schema = h.scheming_get_group_schema(group_type) -%} + {%- snippet 'scheming/snippets/errors.html', + errors=errors, fields=schema.fields, + entity_type='group', object_type=group_type -%} + {%- endif -%} + {% endblock %} {{ h.csrf_input() if 'csrf_input' in h }} {%- set schema = h.scheming_get_group_schema(group_type) -%} {%- for field in schema['fields'] -%} diff --git a/ckanext/scheming/templates/scheming/organization/group_form.html b/ckanext/scheming/templates/scheming/organization/group_form.html index ebf78de7..10a82830 100644 --- a/ckanext/scheming/templates/scheming/organization/group_form.html +++ b/ckanext/scheming/templates/scheming/organization/group_form.html @@ -12,6 +12,14 @@ {%- endif -%} + {% block errors %} + {%- if errors -%} + {%- set schema = h.scheming_get_organization_schema(group_type) -%} + {%- snippet 'scheming/snippets/errors.html', + errors=errors, fields=schema.fields, + entity_type='organization', object_type=group_type -%} + {%- endif -%} + {% endblock %} {{ h.csrf_input() if 'csrf_input' in h }} {%- set schema = h.scheming_get_organization_schema(group_type) -%} {%- for field in schema['fields'] -%}