Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Before and After Validators for Groups #428

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading