From c725d9d0c0652fd0e0b013f16154ede0be6d5b99 Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Wed, 30 Oct 2024 20:24:39 +0100 Subject: [PATCH] Rely on API method to reindex new Sample objects --- src/bika/lims/api/__init__.py | 16 +++++++++++++--- src/bika/lims/utils/analysisrequest.py | 18 +----------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/bika/lims/api/__init__.py b/src/bika/lims/api/__init__.py index 996cbf00d0..9e0bfb441c 100644 --- a/src/bika/lims/api/__init__.py +++ b/src/bika/lims/api/__init__.py @@ -384,10 +384,11 @@ def move_object(obj, destination, check_constraints=True): return obj -def uncatalog_object(obj): +def uncatalog_object(obj, recursive=False): """Un-catalog the object from all catalogs :param obj: object to un-catalog + :param recursive: recursively uncatalog all child objects :type obj: ATContentType/DexterityContentType """ # un-catalog from registered catalogs @@ -399,11 +400,16 @@ def uncatalog_object(obj): url = "/".join(obj.getPhysicalPath()[2:]) uid_catalog.uncatalog_object(url) + if recursive: + for child in obj.objectValues(): + uncatalog_object(child, recursive=recursive) -def catalog_object(obj): + +def catalog_object(obj, recursive=False): """Re-catalog the object - :param obj: object to un-catalog + :param obj: object to catalog + :param recursive: recursively catalog all child objects :type obj: ATContentType/DexterityContentType """ if is_at_content(obj): @@ -416,6 +422,10 @@ def catalog_object(obj): uc.catalog_object(obj, url) obj.reindexObject() + if recursive: + for child in obj.objectValues(): + catalog_object(child, recursive=recursive) + def delete(obj, check_permissions=True, suppress_events=False): """Deletes the given object diff --git a/src/bika/lims/utils/analysisrequest.py b/src/bika/lims/utils/analysisrequest.py index 03ae1fba1d..9bd2816073 100644 --- a/src/bika/lims/utils/analysisrequest.py +++ b/src/bika/lims/utils/analysisrequest.py @@ -158,7 +158,7 @@ def create_analysisrequest(client, request, values, analyses=None, # unmark the sample as temporary api.unmark_temporary(ar) # explicit reindexing after sample finalization - reindex(ar) + api.catalog_object(ar) # notify object initialization (also creates a snapshot) event.notify(ObjectInitializedEvent(ar)) @@ -169,22 +169,6 @@ def create_analysisrequest(client, request, values, analyses=None, return ar -def reindex(obj, recursive=False): - """Reindex the object - - :param obj: The object to reindex - :param recursive: If true, all child objects are reindexed recursively - """ - # reindex UID - uid_catalog = api.get_tool("uid_catalog") - uid_catalog.catalog_object(obj, obj._getURL()) - # reindex object in all other catalogs - obj.reindexObject() - if recursive: - for child in obj.objectValues(): - reindex(child) - - def receive_sample(sample, check_permission=False, date_received=None): """Receive the sample without transition """