Skip to content

Commit

Permalink
feat(WIP): add DataCiteMetadata generator
Browse files Browse the repository at this point in the history
Co-authored-by: MonaW <[email protected]>
  • Loading branch information
alee and monaw committed Jan 10, 2024
1 parent 130b68d commit 990dd10
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions django/library/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 990dd10

Please sign in to comment.