Skip to content

Commit

Permalink
fix: update DataCiteMetadata.build_codebase_metadata
Browse files Browse the repository at this point in the history
add description, default publication year to this year if none, updated
identifier and creators fields
  • Loading branch information
monaw authored and alee committed Jun 19, 2024
1 parent f5e698b commit ca941ec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions django/library/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
]
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion django/library/tests/test_codemeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ca941ec

Please sign in to comment.