Passed
Push — master ( 1b1a5c...7b3c17 )
by Jordi
05:45
created

bika.lims.monkey.zcatalog   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 22
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
C searchResults() 0 41 10
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)
0 ignored issues
show
introduced by
The variable orig_uid does not seem to be defined for all execution paths.
Loading history...
38
        derived = filter(lambda an: an.getParentUID != orig_uid, results)
0 ignored issues
show
introduced by
The variable orig_uid does not seem to be defined for all execution paths.
Loading history...
39
        derived_keys = map(lambda an: an.getKeyword, derived)
40
        results = filter(lambda an: an.getKeyword not in derived_keys, primary)
0 ignored issues
show
introduced by
The variable derived_keys does not seem to be defined for all execution paths.
Loading history...
41
        return results + derived
42
43
    # Normal search
44
    return self._catalog.searchResults(REQUEST, used, **kw)
45