diff --git a/invenio_records_lom/resources/serializers/oai/schema.py b/invenio_records_lom/resources/serializers/oai/schema.py index 8b84897..999693e 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 @@ -221,11 +221,12 @@ 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())) - @pre_load + @pre_dump def group_contributes_by_role(self, data: dict, **__: dict) -> dict: """Group contributes by role.""" contributions_by_role = {} @@ -308,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 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,