Skip to content

oarepo_config.vocabulary

oarepo_config.vocabulary

Configuration for vocabulary.

configure_vocabulary(code: str, **kwargs: Any) -> None

Declare a custom controlled vocabulary (a fixed list of allowed values).

Vocabularies are controlled lists of values that records can pick from, such as languages, resource types or licenses. Call this once for each additional vocabulary type your repository needs, to describe it and any extra properties it should have.

Parameters:

Name Type Description Default
code str

A short, unique identifier for the vocabulary, e.g. "languages".

required
**kwargs Any

Extra details describing the vocabulary, typically including name (its display name), description, and props (a description of any extra fields each entry in the vocabulary should have, and how they appear in forms). See the OARepo reference docs for the full list of supported keys.

{}

Calling this multiple times with different code values adds multiple vocabularies; it does not replace previously configured ones.

Invenio configuration variables set:

  • INVENIO_VOCABULARY_TYPE_METADATA - the entry for code is set to kwargs; entries for other vocabulary codes (added by earlier calls) are kept.
Example
config.configure_vocabulary(
    code="languages",
    name=_("Languages"),
    description=_(
        "Language definitions"
    ),
    props={
        "alpha3Code": {
            "description": _(
                "ISO 639-2 standard 3-letter language code"
            ),
            "multiple": False,
            "search": False,
        },
    },
    dump_options=True,
)
Source code in oarepo_config/vocabulary.py
def configure_vocabulary(code: str, **kwargs: Any) -> None:
    """Declare a custom controlled vocabulary (a fixed list of allowed values).

    Vocabularies are controlled lists of values that records can pick
    from, such as languages, resource types or licenses. Call this once
    for each additional vocabulary type your repository needs, to
    describe it and any extra properties it should have.

    Args:
        code: A short, unique identifier for the vocabulary, e.g.
            `"languages"`.
        **kwargs: Extra details describing the vocabulary, typically
            including `name` (its display name), `description`, and
            `props` (a description of any extra fields each entry in
            the vocabulary should have, and how they appear in forms).
            See the
            [OARepo reference docs](https://nrp-cz.github.io/docs/customize/configure/reference#configure_vocabulary)
            for the full list of supported keys.

    Calling this multiple times with different `code` values adds
    multiple vocabularies; it does not replace previously configured
    ones.

    Invenio configuration variables set:

    * `INVENIO_VOCABULARY_TYPE_METADATA` - the entry for `code` is
      set to `kwargs`; entries for other vocabulary codes (added by
      earlier calls) are kept.

    Example:
        ```python
        config.configure_vocabulary(
            code="languages",
            name=_("Languages"),
            description=_(
                "Language definitions"
            ),
            props={
                "alpha3Code": {
                    "description": _(
                        "ISO 639-2 standard 3-letter language code"
                    ),
                    "multiple": False,
                    "search": False,
                },
            },
            dump_options=True,
        )
        ```

    """
    INVENIO_VOCABULARY_TYPE_METADATA = get_constant_from_caller("INVENIO_VOCABULARY_TYPE_METADATA", {})
    INVENIO_VOCABULARY_TYPE_METADATA[code] = kwargs

    set_constants_in_caller(locals())