diff --git a/django/library/models.py b/django/library/models.py index fdda9d617..2ed800090 100644 --- a/django/library/models.py +++ b/django/library/models.py @@ -1508,6 +1508,10 @@ def codemeta(self): """Returns a CodeMeta object that can be dumped to json""" return CodeMeta.build(self) + @cached_property + def datacite_metadata(self): + return DataCiteMetadata.build(self) + @property def is_draft(self): return self.status == self.Status.DRAFT @@ -2333,6 +2337,22 @@ def __str__(self): return f"[peer review] {invitation.candidate_reviewer} submitted? {self.reviewer_submitted}, recommendation: {self.get_recommendation_display()}" +class DataCiteMetadata: + def __init__(self, metadata: dict): + if not metadata: + raise ValueError( + "Initialize with a base dictionary with DataCite terms mapped to JSON-serializable values" + ) + self.metadata = metadata + + @classmethod + def build(cls, release: CodebaseRelease): + metadata = cls.INITIAL_METADATA.copy() + # FIXME: map all metadata in the given release to DataCite terms + # https://codemeta.github.io/crosswalk/datacite/ + return DataCiteMetadata(metadata) + + class CodeMeta: DATE_PUBLISHED_FORMAT = "%Y-%m-%d" COMSES_ORGANIZATION = {