Skip to main content

Support for custom fields and hierarchy on Invenio vocabularies

Project description

OARepo vocabularies

This is an extension of invenio vocabularies that allows:

  • Use the vocabularies with custom fields
  • Treat vocabulary items as hierarchy

Installation

Add oarepo-runtime, oarepo-vocabularies to your virtualenv an set up the following in your invenio.cfg:

from oarepo_vocabularies.services.config import VocabulariesConfig
from oarepo_vocabularies.resources.config import VocabulariesResourceConfig

VOCABULARIES_SERVICE_CONFIG = VocabulariesConfig
VOCABULARIES_RESOURCE_CONFIG = VocabulariesResourceConfig

Documentation

See NRP documentation for more details.

Authorities

It is possible to provide authority sources for vocabularies. Configuration:

VOCABULARY_TYPE_METADATA = {
    "funding": {    # vocabulary of funding
        "name": {
            "en": "Funding"
        },
        "authority": FundingService
    }
}

where:

from oarepo_vocabularies.authorities import AuthorityService

class FundingService(AuthorityService):
    def search(self, query=None, page=1, size=10, **kwargs):
        # performs an API and returns a listing 
        # of serialized vocabulary items, for example:
        return {
            'hits': {
                'total': 2,
                'hits': [
                    {"id": "03zsq2967", "title": {"en": "Funding 1"}},
                    {"id": "a4gfhtt56", "title": {"en": "Funding 2"}}
                ]
            },
            # optional pagination links here
        }
    def get(self, item_id, *, uow, value, **kwargs):
        # performs lookup by id and returns vocabulary metadata
        
        # in this example:
        return next(x for x in self.search()['hits']['hits'] if x['id'] == item_id)

Ordering

To support other than English ordering, sort custom field has been added to the vocabulary api. This custom field automatically populates sort.<lang> mapping property for each language specified in the configuration:

# invenio.cfg
from oarepo_runtime.cf.icu import ICUSortCF

OAREPO_VOCABULARIES_SORT_CF = [ICUSortCF("cs", "czech", "title.cs")]

When set up this way, the pre-fetched vocabularies (for ui inputs etc) are sorted as well.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

oarepo-vocabularies-2.0.48.tar.gz (79.5 kB view hashes)

Uploaded Source

Built Distribution

oarepo_vocabularies-2.0.48-py3-none-any.whl (129.8 kB view hashes)

Uploaded Python 3

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