Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions site/cds_rdm/administration/clc_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class CLCSyncListView(CLCSyncAdminMixin, AdminResourceListView):
item_field_list = {
"created": {"text": _("Created"), "order": 1, "width": 4},
"clc_record_pid": {"text": _("CLC record"), "order": 2, "width": 2},
"parent_record_pid": {"text": _("CDS record"), "order": 3, "width": 2},
"parent_record_pid": {"text": _("CDS parent record"), "order": 3, "width": 2},
"latest_record_pid": {"text": _("CDS latest record"), "order": 3, "width": 2},
"status": {"text": _("Status"), "order": 4, "width": 2},
"message": {"text": _("Message"), "order": 4, "width": 3},
"auto_sync": {"text": _("Auto sync"), "order": 5, "width": 1},
Expand All @@ -72,7 +73,8 @@ class CLCSyncDetailView(CLCSyncAdminMixin, AdminResourceDetailView):
item_field_list = {
"created": {"text": _("Created"), "order": 1},
"clc_record_pid": {"text": _("CLC record"), "order": 2},
"parent_record_pid": {"text": _("CDS record"), "order": 3},
"parent_record_pid": {"text": _("CDS parent record"), "order": 3},
"latest_record_pid": {"text": _("CDS latest record"), "order": 3},
"status": {"text": _("Status"), "order": 4},
"message": {"text": _("Message"), "order": 5},
"last_sync": {"text": _("Last sync"), "order": 5},
Expand Down
16 changes: 16 additions & 0 deletions site/cds_rdm/clc_sync/services/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"""CDS-RDM CLC schema sync module."""

from flask import current_app
from invenio_access.permissions import system_identity
from invenio_pidstore.errors import PIDDoesNotExistError
from invenio_rdm_records.proxies import current_rdm_records
from marshmallow import EXCLUDE, Schema, fields

from cds_rdm.clc_sync.models import SyncStatusEnum
Expand All @@ -30,6 +33,19 @@ class Meta:
id = fields.String(dump_only=True)
clc_url = fields.Method(serialize="get_clc_url", dump_only=True)
last_sync = fields.DateTime(format="iso", allow_none=True)
latest_record_pid = fields.Method(serialize="get_latest_record_pid", dump_only=True)

def get_latest_record_pid(self, obj):
"""Get the latest record PID."""
if not obj.parent_record_pid:
return None
try:
record = current_rdm_records.records_service.read_latest(
system_identity, obj.parent_record_pid
)
return str(record.id)
except PIDDoesNotExistError:
return None

def get_clc_url(self, obj):
"""Generate the CLC URL for the record."""
Expand Down