From ca941ec2761305671a760f4d209905a99e9d2267 Mon Sep 17 00:00:00 2001 From: Mona Wong Date: Fri, 24 May 2024 17:58:13 -0700 Subject: [PATCH] fix: update DataCiteMetadata.build_codebase_metadata add description, default publication year to this year if none, updated identifier and creators fields --- django/library/models.py | 22 ++++++++++++++++++---- django/library/tests/test_codemeta.py | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/django/library/models.py b/django/library/models.py index f1bd6ab73..7a885c5d2 100644 --- a/django/library/models.py +++ b/django/library/models.py @@ -7,7 +7,7 @@ from typing import List import uuid from collections import OrderedDict -from datetime import timedelta +from datetime import datetime, timedelta import semver from django.conf import settings @@ -2707,10 +2707,11 @@ def build_codebase_metadata(cls, codebase: Codebase): metadata = {} # FIXME: set more codebase attributes??? # https://support.datacite.org/docs/what-is-the-identifiers-attribute-in-the-rest-api + # future consideration: adding references_text and associated_publication_text fields when more info for those fiels are added metadata["identifiers"] = [ { - "identifierType": "URL", + "identifierType": "DOI", # only "DOI" allowed according to DataCite schema "identifier": codebase.permanent_url, } ] @@ -2724,21 +2725,34 @@ def build_codebase_metadata(cls, codebase: Codebase): ) # FIXME: creators should never be empty! + # FIXME: when additional info is available for codebase creator, update this metadata["creators"] = [ - {"name": author_string_name} for author_string_name in codebase.author_list + {"name": author_string_name, "creatorType": "Personal"} + for author_string_name in codebase.author_list ] metadata["titles"] = [{"title": codebase.title}] + metadata["descriptions"] = [ + { + "description": codebase.summarized_description, + "descriptionType": "Abstract", + } + ] # or codebase.description.raw? # FIXME: include more info! metadata["publisher"] = str( f'{CommonMetadata.COMSES_ORGANIZATION["name"]} {CommonMetadata.COMSES_ORGANIZATION["url"]}' ) + + # Use this year if no publication year found + currentDateTime = datetime.now() + date = currentDateTime.date() + year = date.strftime("%Y") metadata["publicationYear"] = str( codebase.first_published_at.year if codebase is not None and codebase.first_published_at is not None and codebase.first_published_at.year is not None - else None + else year ) metadata["types"] = {"resourceType": "Model", "resourceTypeGeneral": "Software"} metadata["schemaVersion"] = "http://datacite.org/schema/kernel-4" diff --git a/django/library/tests/test_codemeta.py b/django/library/tests/test_codemeta.py index 0aa954eef..eb27bdfbb 100644 --- a/django/library/tests/test_codemeta.py +++ b/django/library/tests/test_codemeta.py @@ -4,7 +4,7 @@ import random import string -from django.contrib.auth.models import get_user_model +from django.contrib.auth import get_user_model from hypothesis import ( HealthCheck, Verbosity,