Skip to main content

OArepo references

OArepo module for tracking and updating references in Invenio records

Installation

To use this module in your Invenio application, run the following in your virtual environment:

    pip install oarepo-references

Prerequisites

This module expects a canonical_url field present on your Record model. This field should contain a full canonical url reference to the Record instance, e.g.

class Record(FilesRecord):
    @property
    def canonical_url(self):
        return url_for('invenio_records_rest.recid_item',
                       pid_value=self['pid'], _external=True)

Types of reference

This module considers the following two types of reference that can occur the referencing objects:

Reference by link

Reference to another object is represented in the referencing object's metadata as a canonical_url of the referenced object, e.g:

{
...
  "links": {
    "attachments": "https://example.org/objects/M249/attachments",
    "self": "https://example.org/objects/M249",
    "works": "https://example.org/objects/M249/works"
  }
}

Inlined reference

The actual metadata content of the referenced object are inlined into the referencing object's metadata, e.g:

{
  ...
    "stylePeriod": {
        "id":	123,
        "level": 1,
        "links": {},
        "path": "/novovek-moderni-doba",
        "slug":	"novovek-moderni-doba",
        "startYear": 1789,
        "title": [],
        "tooltip": ""
    }
}

In the example above, the complete metadata of a certain Taxonomic record are inlined into the stylePeriod field of the referencing object.

Usage

To enable reference tracking on your data model objects, you will need to do the following:

  • Tell Marshmallow, which fields of your marshmallow schema contain references by link by inheriting ReferenceByLinkFieldMixin:
class URLReferenceField(ReferenceByLinkFieldMixin, URL):
    """URL reference marshmallow field."""
  • If your Marshmallow Scheme holds inlined references, you will need to define a custom nested schema for inlined reference contents, that implements ref_url that returns an URL to be used as a reference to the object and inherits from InlineReferenceMixin, like this:
class InlinedReferenceSchema(InlineReferenceMixin, Schema):
    """Inlined reference schema."""
    class Meta:
        unknown = INCLUDE

    def ref_url(self, data):
        return data.get('links').get('self')

    def ref_uuid(self, data):
        return data.get('id', None)
  • Use the reference-enabled field in your Marshmallow schema:
class ExampleReferencesSchema(Schema):
    """Reference to other objects schema."""
    link = URLReferenceField()
    inlined = Nested(InlinedReferenceSchema)
  • Inherit your Record model from the ReferenceEnabledRecordMixin and MarshmallowValidatedRecordMixin. Doing so, will add support for automatic Record updates whenever some reference contained in Record metadata changes:
class ExampleRecord(MarshmallowValidatedRecordMixin,
                    ReferenceEnabledRecordMixin,
                    Record):
    """References enabled example record class."""
    MARSHMALLOW_SCHEMA = ExampleReferencesSchema
    VALIDATE_MARSHMALLOW = True
    VALIDATE_PATCH = True

    @property
    def canonical_url(self):
        return url_for('invenio_records_rest.recid_item',
                       pid_value=self['pid'], _external=True)

Signals

This module will register the following signal handlers on the Invenio Records signals that handle managing of reference records whenever a Record changes:

Invenio Records signal Registered signal handler Description
after_record_insert create_references_record Finds all references to other objects in a Record and creates RecordReference entries for each reference
after_record_update update_references_record Updates all RecordReferences that refer to the updated object and reindexes all referring Records
after_record_delete delete_references_record Deletes all RecordReferences referring to the deleted Record

Module API

You can access all the API functions this module exposes through the current_references proxy. For more info, see api.py.

Tasks

An asynchronous (Celery) tasks could be launched in a group on all objects referring to a certain Record like this:

from oarepo_references.utils import run_task_on_referrers

run_task_on_referrers(referred,
                      task.s(),
                      success_task.s(),
                      error_task.s())

Further documentation is available on https://oarepo-references.readthedocs.io/

.. Copyright (C) 2019 Miroslav Bauer, CESNET.

oarepo-references is free software; you can redistribute it and/or
modify it under the terms of the MIT License; see LICENSE file for more
details.

Changes

Version 0.1.0 (released TBD)

  • Initial public release.

Release files for oarepo-references 1.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oarepo-references 1.12.0
File Size Uploaded
oarepo-references-1.12.0.tar.gz 19.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for oarepo-references 1.12.0
File Interpreter ABI Platform
oarepo_references-1.12.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 48.3 kB

Release files / oarepo-references-1.12.0.tar.gz

Download URL oarepo-references-1.12.0.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3370daf59b6f4916bdbcf853310959600a00082c0d4f52528768ceea105b8067
BLAKE2b-256 checksum
How to use checksums
373dc88523f50330c1226f474ed87a958da5a7268b6cfbd8f32623d50ae1402c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release files / oarepo_references-1.12.0-py2.py3-none-any.whl

Download URL oarepo_references-1.12.0-py2.py3-none-any.whl
Size 29.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
524f5a4217fe49d5a0b716875ab4b424ffe83c417ed91e75c6abab9dbb49bce3
BLAKE2b-256 checksum
How to use checksums
6b1b5e7370d7ce828111c079265ed5f3a61c3e83ddaa4dd19ed83374ed4b7393
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page