Skip to content

Commit b159fd4

Browse files
authored
Purge ComputedField fields from AnalysisRequest related with Profiles (#2213)
* Remove ProfilesUID computed field * Added upgrade step * Remove ProfilesURL * Remove getProfilesTitle * Remove ProfilesTitleStr * Clarifying message * Changelog
1 parent f9f320f commit b159fd4

File tree

7 files changed

+59
-35
lines changed

7 files changed

+59
-35
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
2.4.0 (unreleased)
55
------------------
66

7+
- #2213 Purge ComputedField fields from AnalysisRequest related with Profiles
78
- #2212 Improve performance of legacy AT `UIDReferenceField`'s getter
89
- #2211 Remove `Profile` field (stale) from AnalysisRequest
910
- #2207 Support for file upload on analysis (pre) conditions

src/bika/lims/content/analysisrequest.py

+6-29
Original file line numberDiff line numberDiff line change
@@ -1098,15 +1098,6 @@
10981098
),
10991099
),
11001100

1101-
ComputedField(
1102-
'ProfilesUID',
1103-
expression="[p.UID() for p in here.getProfiles()] " \
1104-
"if here.getProfiles() else []",
1105-
widget=ComputedWidget(
1106-
visible=False,
1107-
),
1108-
),
1109-
11101101
ComputedField(
11111102
'Invoiced',
11121103
expression='here.getInvoice() and True or False',
@@ -1188,24 +1179,6 @@
11881179
"if here.getStorageLocation() else ''",
11891180
widget=ComputedWidget(visible=False),
11901181
),
1191-
ComputedField(
1192-
'ProfilesURL',
1193-
expression="[p.absolute_url_path() for p in here.getProfiles()] " \
1194-
"if here.getProfiles() else []",
1195-
widget=ComputedWidget(visible=False),
1196-
),
1197-
ComputedField(
1198-
'ProfilesTitle',
1199-
expression="[p.Title() for p in here.getProfiles()] " \
1200-
"if here.getProfiles() else []",
1201-
widget=ComputedWidget(visible=False),
1202-
),
1203-
ComputedField(
1204-
'ProfilesTitleStr',
1205-
expression="', '.join([p.Title() for p in here.getProfiles()]) " \
1206-
"if here.getProfiles() else ''",
1207-
widget=ComputedWidget(visible=False),
1208-
),
12091182
ComputedField(
12101183
'TemplateUID',
12111184
expression="here.getTemplate().UID() if here.getTemplate() else ''",
@@ -1509,8 +1482,12 @@ def getClient(self):
15091482
return self.aq_parent.getClient()
15101483
return None
15111484

1512-
def getProfilesTitle(self):
1513-
return [profile.Title() for profile in self.getProfiles()]
1485+
def getProfilesTitleStr(self):
1486+
"""Returns a comma-separated string withg the titles of the profiles
1487+
assigned to this Sample. Used to populate a metadata field
1488+
"""
1489+
profiles = [profile.Title() for profile in self.getProfiles()]
1490+
return ", ".join(profiles)
15141491

15151492
def getAnalysisService(self):
15161493
proxies = self.getAnalyses(full_objects=False)

src/senaite/core/browser/samples/view.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ def __init__(self, context, request):
201201
"toggle": False}),
202202
("getProfilesTitle", {
203203
"title": _("Profile"),
204-
"sortable": True,
205-
"index": "getProfilesTitle",
204+
"sortable": False,
206205
"toggle": False}),
207206
("getAnalysesNum", {
208207
"title": _("Number of Analyses"),

src/senaite/core/catalog/sample_catalog.py

-3
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@
7272
"getPhysicalPath",
7373
"getPrinted",
7474
"getPrioritySortkey",
75-
"getProfilesTitle",
7675
"getProfilesTitleStr",
77-
"getProfilesUID",
78-
"getProfilesURL",
7976
"getProgress",
8077
"getProvince",
8178
"getRawParentAnalysisRequest",

src/senaite/core/profiles/default/metadata.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<metadata>
3-
<version>2405</version>
3+
<version>2406</version>
44
<dependencies>
55
<dependency>profile-Products.ATContentTypes:base</dependency>
66
<dependency>profile-Products.CMFEditions:CMFEditions</dependency>

src/senaite/core/upgrade/v02_04_000.py

+40
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from bika.lims.interfaces import IRetracted
2828
from senaite.core import logger
2929
from senaite.core.catalog import ANALYSIS_CATALOG
30+
from senaite.core.catalog import SAMPLE_CATALOG
3031
from senaite.core.config import PROJECTNAME as product
3132
from senaite.core.upgrade import upgradestep
3233
from senaite.core.upgrade.utils import UpgradeUtils
@@ -188,3 +189,42 @@ def fix_traceback_retract_dl(tool):
188189
obj._p_deactivate()
189190

190191
logger.info("Migrate LDL, UDL and result fields to string [DONE]")
192+
193+
194+
def purge_computed_fields_profile(self):
195+
"""Cleanup of computed fields related with Profiles field and removal of
196+
indexes and columns that are no longer required
197+
"""
198+
logger.info("Purge ComputedField from Sample related with Profiles ...")
199+
indexes_to_remove = [
200+
]
201+
columns_to_remove = [
202+
("getProfilesUID", SAMPLE_CATALOG),
203+
("getProfilesURL", SAMPLE_CATALOG),
204+
("getProfilesTitle", SAMPLE_CATALOG),
205+
]
206+
207+
# Purge the catalogs
208+
purge_catalogs(indexes_to_remove, columns_to_remove)
209+
210+
logger.info("Purge ComputedField from Sample related with Profiles [DONE]")
211+
212+
213+
def purge_catalogs(indexes_to_remove, columns_to_remove):
214+
"""Removes the indexes and columns from catalogs
215+
"""
216+
# remove indexes
217+
for index_name, catalog_id in indexes_to_remove:
218+
cat = api.get_tool(catalog_id)
219+
if index_name in cat.indexes():
220+
logger.info("Removing '{}' index from '{}'".format(
221+
index_name, catalog_id))
222+
cat.delIndex(index_name)
223+
224+
# remove columns
225+
for col_name, catalog_id in columns_to_remove:
226+
cat = api.get_tool(catalog_id)
227+
if col_name in cat.schema():
228+
logger.info("Removing '{}' column from '{}'".format(
229+
col_name, catalog_id))
230+
cat.delColumn(col_name)

src/senaite/core/upgrade/v02_04_000.zcml

+10
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,14 @@
5353
handler="senaite.core.upgrade.v02_04_000.fix_traceback_retract_dl"
5454
profile="senaite.core:default"/>
5555

56+
<!-- Purge ComputedField from AnalysisRequest related with Profiles
57+
https://github.com/senaite/senaite.core/pull/2213 -->
58+
<genericsetup:upgradeStep
59+
title="SENAITE CORE 2.4.0: Purge ComputedField from AnalysisRequest related with Profiles"
60+
description="Purge ComputedField from AnalysisRequest related with Profiles"
61+
source="2405"
62+
destination="2406"
63+
handler="senaite.core.upgrade.v02_04_000.purge_computed_fields_profile"
64+
profile="senaite.core:default"/>
65+
5666
</configure>

0 commit comments

Comments
 (0)