1
|
|
|
from bika.lims.catalog.analysis_catalog import CATALOG_ANALYSIS_LISTING |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
def searchResults(self, REQUEST=None, used=None, **kw): |
5
|
|
|
"""Search the catalog |
6
|
|
|
|
7
|
|
|
Search terms can be passed in the REQUEST or as keyword |
8
|
|
|
arguments. |
9
|
|
|
|
10
|
|
|
The used argument is now deprecated and ignored |
11
|
|
|
""" |
12
|
|
|
if REQUEST and REQUEST.get('getRequestUID') \ |
13
|
|
|
and self.id == CATALOG_ANALYSIS_LISTING: |
14
|
|
|
|
15
|
|
|
# Fetch all analyses that have the request UID passed in as an ancestor, |
16
|
|
|
# cause we want Primary ARs to always display the analyses from their |
17
|
|
|
# derived ARs (if result is not empty) |
18
|
|
|
|
19
|
|
|
request = REQUEST.copy() |
20
|
|
|
orig_uid = request.get('getRequestUID') |
21
|
|
|
|
22
|
|
|
# If a list of request uid, retrieve them sequentially to make the |
23
|
|
|
# masking process easier |
24
|
|
|
if isinstance(orig_uid, list): |
25
|
|
|
results = list() |
26
|
|
|
for uid in orig_uid: |
27
|
|
|
request['getRequestUID'] = [uid] |
28
|
|
|
results += self.searchResults(REQUEST=request, used=used, **kw) |
29
|
|
|
return results |
30
|
|
|
|
31
|
|
|
# Get all analyses, those from descendant ARs included |
32
|
|
|
del request['getRequestUID'] |
33
|
|
|
request['getAncestorsUIDs'] = orig_uid |
34
|
|
|
results = self.searchResults(REQUEST=request, used=used, **kw) |
35
|
|
|
|
36
|
|
|
# Masking |
37
|
|
|
primary = filter(lambda an: an.getParentUID == orig_uid, results) |
|
|
|
|
38
|
|
|
derived = filter(lambda an: an.getParentUID != orig_uid, results) |
|
|
|
|
39
|
|
|
derived_keys = map(lambda an: an.getKeyword, derived) |
40
|
|
|
results = filter(lambda an: an.getKeyword not in derived_keys, primary) |
|
|
|
|
41
|
|
|
return results + derived |
42
|
|
|
|
43
|
|
|
# Normal search |
44
|
|
|
return self._catalog.searchResults(REQUEST, used, **kw) |
45
|
|
|
|