@@ -5,7 +5,8 @@ This CKAN extension provides a way to configure and share metadata schemas using
55YAML or JSON schema description. Custom validation and template snippets for editing
66and display are supported.
77
8- [ ![ Tests] ( https://github.com/ckan/ckanext-scheming/workflows/Tests/badge.svg?branch=master )] ( https://github.com/ckan/ckanext-scheming/actions )
8+ [ ![ Tests] ( https://github.com/ckan/ckanext-scheming/actions/workflows/test.yml/badge.svg )] ( https://github.com/ckan/ckanext-scheming/actions )
9+
910
1011Table of contents:
1112
@@ -14,19 +15,18 @@ Table of contents:
14153 . [ Configuration] ( #configuration )
1516 - [ Schema Types] ( #schema-types )
1617 - [ Example Schemas] ( #example-schemas )
17- - [ Storing non-string data] ( #storing-non-string-data )
1818 - [ Common Schema Keys] ( #common-schema-keys )
1919 - [ ` scheming_version ` ] ( #scheming_version )
2020 - [ ` about_url ` ] ( #about_url )
21+ - [ ` before_validators ` , ` after_validators ` ] ( #before_validators-after_validators )
2122 - [ Dataset Schema Keys] ( #dataset-schema-keys )
2223 - [ ` dataset_type ` ] ( #dataset_type )
2324 - [ ` dataset_fields ` , ` resource_fields ` ] ( #dataset_fields-resource_fields )
24- - [ ` before_validators ` , ` after_validators ` ] ( #before_validators-after_validators )
25+ - [ ` draft_fields_required ` ] ( #draft_fields_required )
2526 - [ Group / Organization Schema Keys] ( #group--organization-schema-keys )
2627 - [ ` group_type ` ] ( #group_type )
2728 - [ ` organization_type ` ] ( #organization_type )
2829 - [ ` fields ` ] ( #fields )
29- - [ ` before_validators ` , ` after_validators ` ] ( #before_validators-after_validators-1 )
3030 - [ Field Keys] ( #field-keys )
3131 - [ ` field_name ` ] ( #field_name )
3232 - [ ` label ` ] ( #label )
@@ -113,6 +113,7 @@ Dataset schemas:
113113* [ camel photos schema] ( ckanext/scheming/camel_photos.yaml )
114114* [ subfields schema] ( ckanext/scheming/subfields.yaml )
115115* [ form pages schema] ( ckanext/scheming/ckan_formpages.yaml )
116+ * [ form pages schema with ` draft_fields_required: false ` ] ( ckanext/scheming/ckan_formpages_draft.yaml )
116117
117118These schemas are included in ckanext-scheming and may be enabled
118119with e.g: ` scheming.dataset_schemas = ckanext.scheming:camel_photos.yaml `
@@ -196,7 +197,25 @@ before_validators: validator_name
196197after_validators: validator_name
197198` ` `
198199
199- Runs validator functions before and after the `dataset_type` package is created/updated.
200+ Runs validator functions before and after the `dataset_type` package or `organization_type`/`group_type` group is created/updated.
201+
202+ See [`validators`](#validators) for a description of the values accepted.
203+
204+ # ## `draft_fields_required`
205+
206+ Enforce required fields even if a dataset is still in draft state.
207+ Default : ` true`
208+
209+ ` ` ` yaml
210+ draft_fields_required: false
211+ ` ` `
212+
213+ > [!NOTE]
214+ > Setting `draft_fields_required: false` is only supported by **_CKAN 2.12+_** or with https://github.com/ckan/ckan/pull/8309 .
215+
216+ Set to `false` to allow saving dataset and resource metadata even
217+ if some *required fields* have not been provided as long as the dataset
218+ is still in *draft* state (has not been published).
200219
201220
202221# # Group / Organization Schema Keys
@@ -241,21 +260,9 @@ fields:
241260
242261...
243262` ` `
244- A single `fields` list replaces the `dataset_fields` and `resource_fields` schema properties doin dataset schemas.
263+ A single `fields` list replaces the `dataset_fields` and `resource_fields` schema properties in dataset schemas.
245264
246265
247- # ## `before_validators`, `after_validators`
248-
249- ` ` ` yaml
250- before_validators: validator_name
251-
252- after_validators: validator_name
253- ` ` `
254-
255- Runs validator functions before and after the `organization_type`/`group_type` group is created/updated.
256-
257-
258- ----------------
259266
260267# # Field Keys
261268# ## `field_name`
@@ -304,7 +311,8 @@ When using a plain string translations will be provided with gettext:
304311This field is the parent of group of repeating subfields. The value is
305312a list of fields entered the same way as normal fields.
306313
307- > **_NOTE:_** CKAN needs an IPackageController plugin with `before_index` to
314+ > [!NOTE]
315+ > CKAN needs an IPackageController plugin with `before_index` to
308316> convert repeating subfields to formats that can be indexed by solr. For
309317> testing you may use the included `scheming_nerf_index` plugin to encode
310318> all repeating fields as JSON strings to prevent solr errors.
@@ -333,9 +341,12 @@ for each group.
333341# ## `start_form_page`
334342
335343Dataset fields may be divided into separate form pages for creation
336- and editing. **_CKAN 2.9+ only_**. Form pages for `dataset` type
337- only supported by **_CKAN 2.10+_** or with https://github.com/ckan/ckan/pull/7032
338- . Adding `start_form_page` to a field marks this field as the start of a
344+ and editing.
345+
346+ > [!NOTE]
347+ > Form pages for `dataset` type is only supported by **_CKAN 2.10+_** or with https://github.com/ckan/ckan/pull/7032 .
348+
349+ Adding `start_form_page` to a field marks this field as the start of a
339350new page of fields.
340351
341352
@@ -364,13 +375,7 @@ Use for fields that must be included. Set to `false` or
364375don't include this key for fields that are optional.
365376
366377Setting to `true` will mark the field as required in the editing form
367- and include `not_empty` in the default validators that will be applied
368- when `validators` is not specified.
369-
370- > **_NOTE:_** To honor this settings with custom validators include `scheming_required`
371- > as the first validator. `scheming_required` will check the required
372- > setting for this field and apply either the `not_empty` or `ignore_missing`
373- > validator.
378+ and affects the behavior of the `scheming_required` field validator.
374379
375380
376381# ## `choices`
@@ -587,40 +592,50 @@ Set a `property` attribute on dataset fields displayed as "Additional Info", use
587592# ## `validators`
588593
589594The `validators` value is a space-separated string of validator and converter
590- functions to use for this field when creating or updating data. When a
591- validator name is followed by parenthesis the function is called passing the
592- comma-separated values within and the result is used as the
595+ functions to use for this field when creating or updating data. For core fields
596+ the validators default to the ones defined in the CKAN core schemas.
597+
598+ > [!WARNING]
599+ > Use `scheming_required` as the first validator
600+ > or the [`required`](#required) field setting will be ignored.
601+ > `scheming_required` applies either the `not_empty` or `ignore_missing`
602+ > validator based on the `required` field setting.
603+
604+ When a validator name is followed by parenthesis the function is called
605+ passing the comma-separated values within and the result is used as the
593606validator/converter.
594607
595608` ` ` yaml
596- validators: if_empty_same_as(name) unicode_safe
609+ validators: scheming_required if_empty_same_as(name) unicode_safe
597610` ` `
598611
599- is the same as a plugin using the validators :
612+ is the same as a form plugin using the validators :
600613
601614` ` ` python
602- [get_validator('if_empty_same_as')("name"), unicode_safe]
615+ [
616+ get_validator('scheming_required'),
617+ get_validator('if_empty_same_as')("name"),
618+ get_validator('unicode_safe')
619+ ]
603620` ` `
604621
605- If parameters can be parsed as a valid python literals, they are passed with
606- original type. If not, all parameters passed as strings. In addition, space
607- character is not allowed in argument position. Use its HEX code instead `\\x20`.
622+ If validator parameters can be parsed as a valid python literals,
623+ they are passed with the original type. If not, all parameters passed
624+ as strings. In addition, space character is not allowed in argument
625+ position. Use its HEX code instead `\\x20`.
608626
609627` ` ` yaml
610- validators: xxx(hello,world) # xxx("hello", "world")
611- validators: xxx(hello,1) # xxx("hello", "1")
612- validators: xxx("hello",1,None) # xxx("hello", 1, None)
628+ validators: xxx(hello,world) # xxx("hello", "world")
629+ validators: xxx(hello,1) # xxx("hello", "1")
630+ validators: xxx("hello",1,None) # xxx("hello", 1, None)
613631 validators: xxx("hello\\ x20world") # xxx("hello world")
614632` ` `
615633
616- This string does not contain arbitrary python code to be executed,
617- you may only use registered validator functions, optionally calling
618- them with static string values provided.
619-
620- > **_NOTE:_** ckanext-scheming automatically adds calls to `convert_to_extras`
634+ > [!NOTE]
635+ > ckanext-scheming automatically adds a call to `convert_to_extras`
621636> for extra fields when required.
622637
623- New validators and converters may be added using the
638+ New validators and converters may be registered using the
624639[IValidators plugin interface](http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html?highlight=ivalidator#ckan.plugins.interfaces.IValidators).
625640
626641Validators that need access to other values in this schema (e.g.
@@ -657,7 +672,8 @@ retrieving values from the database instead of when saving them.
657672These validators may be used to transform the data before it is
658673sent to the user.
659674
660- > **_NOTE:_** ckanext-scheming automatically adds calls to `convert_from_extras`
675+ > [!NOTE]
676+ > ckanext-scheming automatically adds calls to `convert_from_extras`
661677> for extra fields when required.
662678
663679### `create_validators`
0 commit comments