Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various changes to OAI-PMH output for compatibility #173

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions invenio_records_lom/resources/serializers/oai/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
martinobersteiner marked this conversation as resolved.
Show resolved Hide resolved
def group_contributes_by_role(self, data: dict, **__: dict) -> dict:
"""Group contributes by role."""
contributions_by_role = {}
Expand Down Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions invenio_records_lom/services/schemas/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand All @@ -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."""

Expand Down Expand Up @@ -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,
Expand Down