Skip to content

Commit

Permalink
Merge pull request #428 from JVickery-TBS/feature/before-after-valida…
Browse files Browse the repository at this point in the history
…tors

Before and After Validators for Groups
  • Loading branch information
wardi authored Nov 8, 2024
2 parents 0438f00 + 86e325f commit 172c2c4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions ckanext/scheming/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions ckanext/scheming/templates/scheming/group/group_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
{%- endif -%}

<form class="dataset-form form-horizontal" method="post" data-module="basic-form" enctype="multipart/form-data">
{% 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'] -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
{%- endif -%}

<form class="dataset-form form-horizontal" method="post" data-module="basic-form" enctype="multipart/form-data">
{% 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'] -%}
Expand Down

0 comments on commit 172c2c4

Please sign in to comment.