Skip to content

Commit

Permalink
cff: add default "message" field
Browse files Browse the repository at this point in the history
  • Loading branch information
slint committed Feb 27, 2025
1 parent b0eab8d commit 4693102
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions invenio_rdm_records/resources/serializers/cff/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class CFFSchema(BaseSerializerSchema):
keywords = fields.Method("get_keywords")
license = fields.Method("get_license")
license_url = fields.Method("get_license_url", data_key="license-url")
message = fields.Method("get_message")
# TODO references - related identifiers?
# TODO there are other derivations of repository
repository_code = fields.Method("get_repository_code", data_key="repository-code")
Expand Down Expand Up @@ -239,3 +240,13 @@ def get_type(self, obj):
return missing

return resource_type

def get_message(self, obj):
"""Get standard citation message based on record type."""
resource_type = obj.get("metadata", {}).get("resource_type", {}).get("id")

type_label = "work"
if resource_type in self.allowed_types:
type_label = resource_type

return f"If you use this {type_label}, please cite it using the metadata from this file."
1 change: 1 addition & 0 deletions tests/resources/serializers/test_cff_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_cff_serializer(running_app, full_record_to_dict):
"license:\n"
"- cc-by-4.0\n"
"license-url: https://customlicense.org/licenses/by/4.0/\n"
"message: If you use this software, please cite it using the metadata from this file.\n"
"repository-code: "
"https://github.com/citation-file-format/cff-converter-python\n"
"title: InvenioRDM\n"
Expand Down

0 comments on commit 4693102

Please sign in to comment.