From e504342b9912ea7ad9ce50470c0264be4243c2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=BCbeyde=20Civelek?= Date: Thu, 11 Dec 2025 16:15:43 +0100 Subject: [PATCH] add(clc sync): display latest record in admin page --- site/cds_rdm/administration/clc_sync.py | 6 ++++-- site/cds_rdm/clc_sync/services/schema.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/site/cds_rdm/administration/clc_sync.py b/site/cds_rdm/administration/clc_sync.py index d39b0199..75c65cc7 100644 --- a/site/cds_rdm/administration/clc_sync.py +++ b/site/cds_rdm/administration/clc_sync.py @@ -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}, @@ -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}, diff --git a/site/cds_rdm/clc_sync/services/schema.py b/site/cds_rdm/clc_sync/services/schema.py index ee31cc07..87e39540 100644 --- a/site/cds_rdm/clc_sync/services/schema.py +++ b/site/cds_rdm/clc_sync/services/schema.py @@ -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 @@ -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."""