From 990dd1028c9bccbd20ae6ae4439f52565dee19f5 Mon Sep 17 00:00:00 2001 From: Allen Lee Date: Wed, 10 Jan 2024 11:59:03 -0700 Subject: [PATCH] feat(WIP): add DataCiteMetadata generator Co-authored-by: MonaW --- django/library/models.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 = {