Skip to main content

"A model builder plugin for custom fields support"

Project description

Custom fields plugin for model builder

Custom fields

Custom fields allow extending model at configuration time, with the same sources. This plugin adds two types of custom fields - ones defined on an explicit element (usually the "custom_fields" element is used, but any name can be used) and other one inlining the custom fields directly to the main content.

Currently there is no support for inlining custom fields to "metadata" element, but this can be changed in the future.

Model file

Custom fields are defined on the level of "model":

model:
    use: invenio
    custom-fields:
    - element: custom_fields
      config: TEST_CUSTOM_FIELDS
    properties:
        metadata:
            properties:
                title: fulltext

Explicit custom fields

Explicit custom fields are defined using a pair of element name and config variable. In the instance the custom fields will be separated into the element name:

# config

from invenio_records_resources.services.custom_fields.text import KeywordCF

TEST_CUSTOM_FIELDS = [
    KeywordCF('blah')
]
// instance
{
    "metadata": {
        "title": "My Title"
    },
    "custom_fields": {                  // "element" from model
        "blah": "Custom field value"    // as defined in "TEST_CUSTOM_FIELDS" variable
    }
}

Inline custom fields

Inline custom fields are placed on the root level of the instance, without an enclosing element. To define them, just leave the element definition. Note that only 1 definition of inline CF is allowed.

model:
    use: invenio
    custom-fields:
    - config: INLINE_CF
    properties:
        metadata:
            properties:
                title: fulltext
# config

from invenio_records_resources.services.custom_fields.text import KeywordCF

INLINE_CF = [
    KeywordCF('blah')
]
// instance
{
    "metadata": {
        "title": "My Title"
    },
    "blah": "Custom field value"    // as defined in "INLINE_CF" variable
}

Custom fields nested in metadata

Custom fields nested inside the metadata are not supported yet.

Using custom fields

Custom fields influence the jsonschema file (adding a non-checked object or allowing additional properties) and the mapping file (adding an empty mapping for CF).

During deployment time, after the index is created and before data are poured in, a specialized mapping for custom fields must be created. To do so, call

invenio oarepo cf init

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oarepo_model_builder_cf-4.0.8.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

oarepo_model_builder_cf-4.0.8-py2.py3-none-any.whl (9.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file oarepo_model_builder_cf-4.0.8.tar.gz.

File metadata

File hashes

Hashes for oarepo_model_builder_cf-4.0.8.tar.gz
Algorithm Hash digest
SHA256 ca590a70cec738d4546cc75c792068e798ffffa7316e39bc06867397c5359b71
MD5 bf4bd70e245caed2f84750dab87dd2d2
BLAKE2b-256 4c88fe05b9d54a15065989cfe3d4a8482a8d0d18a02133c6083d49915082b5fc

See more details on using hashes here.

File details

Details for the file oarepo_model_builder_cf-4.0.8-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for oarepo_model_builder_cf-4.0.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3edc13355ba079fbab1433b3a868dbb009d7f4788c2bbdba39f88f7fdd000d0a
MD5 ca91f76d9644039f71982757d89e02a8
BLAKE2b-256 092e3ef0584b6edf3b2e23ea7bc94fb05a27e9e9b4d7eaba6e48a7386c00d669

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page