Skip to content

Commit

Permalink
feat(dev): group before and after validators;
Browse files Browse the repository at this point in the history
- Added before and after validators to README.
- Added before and after validators to org and group schemas.
- Added error block to group and org form templates.
  • Loading branch information
JVickery-TBS committed Nov 8, 2024
1 parent 27035f4 commit 86e325f
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 @@ -184,6 +184,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 @@ -231,6 +240,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 86e325f

Please sign in to comment.