From 92cc3eb3534040b08769253e4b656b45e8b207c9 Mon Sep 17 00:00:00 2001 From: Martin Obersteiner Date: Tue, 12 Nov 2024 11:10:31 +0100 Subject: [PATCH 1/4] fix: use `pre_dump` for dump-only OAI-schema some past commit rebuilt OAI-schema to use dump over load it missed exchanging `pre_load` for `pre_dump` when doing so --- invenio_records_lom/resources/serializers/oai/schema.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/invenio_records_lom/resources/serializers/oai/schema.py b/invenio_records_lom/resources/serializers/oai/schema.py index 8b84897..21b6b79 100644 --- a/invenio_records_lom/resources/serializers/oai/schema.py +++ b/invenio_records_lom/resources/serializers/oai/schema.py @@ -9,7 +9,7 @@ from copy import copy -from marshmallow import EXCLUDE, Schema, fields, pre_load, validate, validates_schema +from marshmallow import EXCLUDE, Schema, fields, pre_dump, validate, validates_schema from ....services.schemas.metadata import validate_cc_license_lang from ....utils import make_lom_vcard @@ -225,7 +225,7 @@ class LifecycleSchema(ExcludeUnknownOrderedSchema): status = fields.Field() contribute = fields.List(fields.Nested(ContributeSchema())) - @pre_load + @pre_dump def group_contributes_by_role(self, data: dict, **__: dict) -> dict: """Group contributes by role.""" contributions_by_role = {} From 2ead7f6a9f5a3df30ab6a12601a2380d35ee190e Mon Sep 17 00:00:00 2001 From: Martin Obersteiner Date: Tue, 12 Nov 2024 11:10:31 +0100 Subject: [PATCH 2/4] oai: add `lifecycle.datetime` to generated output --- invenio_records_lom/resources/serializers/oai/schema.py | 1 + 1 file changed, 1 insertion(+) diff --git a/invenio_records_lom/resources/serializers/oai/schema.py b/invenio_records_lom/resources/serializers/oai/schema.py index 21b6b79..4371ace 100644 --- a/invenio_records_lom/resources/serializers/oai/schema.py +++ b/invenio_records_lom/resources/serializers/oai/schema.py @@ -221,6 +221,7 @@ def get_centity(self, contributors: dict) -> list: class LifecycleSchema(ExcludeUnknownOrderedSchema): """Schema for LOM-UIBK's `lifecycle` category.""" + datetime = fields.String() version = fields.Field() status = fields.Field() contribute = fields.List(fields.Nested(ContributeSchema())) From 28ec751276480a3e4172d0209290700611be8ede Mon Sep 17 00:00:00 2001 From: Martin Obersteiner Date: Tue, 12 Nov 2024 11:10:31 +0100 Subject: [PATCH 3/4] uploads: add load-default for `lifecycle.datetime` --- invenio_records_lom/services/schemas/metadata.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/invenio_records_lom/services/schemas/metadata.py b/invenio_records_lom/services/schemas/metadata.py index dbf36fe..f29be0e 100644 --- a/invenio_records_lom/services/schemas/metadata.py +++ b/invenio_records_lom/services/schemas/metadata.py @@ -9,6 +9,7 @@ from collections.abc import Callable from copy import copy +from datetime import datetime, timezone from types import MappingProxyType from invenio_i18n import lazy_gettext as _ @@ -25,6 +26,15 @@ from marshmallow_utils.html import sanitize_unicode +def now_isoformat() -> str: + """Return current date and time in ISO-8601 format. + + example-return: '2020-06-24T05:34:56.789123' + """ + now_unaware = datetime.now(timezone.utc).replace(tzinfo=None) + return now_unaware.isoformat() + + class NoValidationSchema(Schema): """Let data through unchanged, without validation.""" @@ -250,6 +260,7 @@ class ContributeSchema(Schema): class LifecycleSchema(Schema): """Schema for LOM's `lifecycle` category.""" + datetime = fields.String(load_default=now_isoformat) contribute = fields.List( fields.Nested(ContributeSchema()), required=True, From bee0163cca1424c43bd41150abd41dd71319328d Mon Sep 17 00:00:00 2001 From: Martin Obersteiner Date: Tue, 12 Nov 2024 11:10:31 +0100 Subject: [PATCH 4/4] oai: change default for learningresourcetype --- invenio_records_lom/resources/serializers/oai/schema.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/invenio_records_lom/resources/serializers/oai/schema.py b/invenio_records_lom/resources/serializers/oai/schema.py index 4371ace..999693e 100644 --- a/invenio_records_lom/resources/serializers/oai/schema.py +++ b/invenio_records_lom/resources/serializers/oai/schema.py @@ -309,12 +309,12 @@ class LearningResourceTypeSchema(ExcludeUnknownOrderedSchema): validate=validate.Equal(LANGSTRING_KIM_HCRT_SCHEME), dump_default=LANGSTRING_KIM_HCRT_SCHEME, ) - id = fields.Str(required=True, dump_default="N/A") + id = fields.Str(required=True, dump_default="https://w3id.org/kim/hcrt/other") @classmethod def dump_default(cls) -> dict: """Dump default.""" - obj = {"id": "N/A"} + obj = {"id": "https://w3id.org/kim/hcrt/other"} obj |= {"source": LANGSTRING_KIM_HCRT_SCHEME} return obj