-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: added service schema for zenodo records
* added export formats in config * override bibtex serializer to include swhid
- Loading branch information
1 parent
305b211
commit 547b7c0
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# Zenodo-RDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Zenodo-RDM service schema.""" | ||
|
||
from invenio_rdm_records.services.schemas import RDMRecordSchema | ||
from marshmallow import Schema, fields | ||
|
||
|
||
class SWHSchema(Schema): | ||
"""Software Heritage schema.""" | ||
|
||
swhid = fields.Str() | ||
|
||
|
||
class ZenodoRecordSchema(RDMRecordSchema): | ||
"""Zenodo service schema. | ||
This schema subclasses the base schema and extends it with Zenodo-specific | ||
fields. | ||
""" | ||
|
||
swh = fields.Nested(SWHSchema, dump_only=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# ZenodoRDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Zenodo serializers.""" | ||
|
||
from .bibtex import ZenodoBibtexSerializer | ||
|
||
__all__ = ("ZenodoBibtexSerializer",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# ZenodoRDM is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
"""Zenodo bibtex serializer.""" | ||
|
||
from flask_resources import BaseListSchema, MarshmallowSerializer | ||
from flask_resources.serializers import SimpleSerializer | ||
from invenio_rdm_records.resources.serializers import BibtexSerializer | ||
from invenio_rdm_records.resources.serializers.bibtex.schema import BibTexSchema | ||
from marshmallow import fields, missing | ||
|
||
|
||
class ZenodoBibtexSchema(BibTexSchema): | ||
"""Zenodo bibtex schema.""" | ||
|
||
swhid = fields.Method("get_swhid") | ||
|
||
def get_swhid(self, obj): | ||
"""Get swhid.""" | ||
return obj.get("swh", {}).get("swhid") or missing | ||
|
||
|
||
class ZenodoBibtexSerializer(MarshmallowSerializer): | ||
"""Zenodo bibtex serializer.""" | ||
|
||
def __init__(self, **options): | ||
"""Initialize serializer.""" | ||
super().__init__( | ||
format_serializer_cls=SimpleSerializer, | ||
object_schema_cls=ZenodoBibtexSchema, | ||
list_schema_cls=BaseListSchema, | ||
encoder=self.bibtex_tostring, | ||
) | ||
|
||
@classmethod | ||
def bibtex_tostring(cls, record): | ||
"""Stringify a BibTex record.""" | ||
return record |