Passed
Push — 2.x ( 699219...f5b4d5 )
by Jordi
07:20
created

senaite.core.catalog.indexer.client   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 17
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A client_searchable_text() 0 22 1
1
# -*- coding: utf-8 -*-
2
3
from bika.lims import api
4
from bika.lims.interfaces import IClient
5
from plone.indexer import indexer
6
from senaite.core.interfaces.catalog import IClientCatalog
7
8
9
@indexer(IClient, IClientCatalog)
10
def client_searchable_text(instance):
11
    """Extract search tokens for ZC text index
12
    """
13
14
    tokens = [
15
        instance.getClientID(),
16
        instance.getName(),
17
        instance.getPhone(),
18
        instance.getFax(),
19
        instance.getEmailAddress(),
20
        instance.getTaxNumber(),
21
    ]
22
23
    # extend address lines
24
    tokens.extend(instance.getPrintAddress())
25
26
    # remove duplicates and filter out emtpies
27
    tokens = filter(None, set(tokens))
28
29
    # return a single unicode string with all the concatenated tokens
30
    return u" ".join(map(api.safe_unicode, tokens))
31