|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# This file is part of SENAITE.CORE. |
|
4
|
|
|
# |
|
5
|
|
|
# SENAITE.CORE is free software: you can redistribute it and/or modify it under |
|
6
|
|
|
# the terms of the GNU General Public License as published by the Free Software |
|
7
|
|
|
# Foundation, version 2. |
|
8
|
|
|
# |
|
9
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
|
10
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
11
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
12
|
|
|
# details. |
|
13
|
|
|
# |
|
14
|
|
|
# You should have received a copy of the GNU General Public License along with |
|
15
|
|
|
# this program; if not, write to the Free Software Foundation, Inc., 51 |
|
16
|
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17
|
|
|
# |
|
18
|
|
|
# Copyright 2018-2023 by it's authors. |
|
19
|
|
|
# Some rights reserved, see README and LICENSE. |
|
20
|
|
|
|
|
21
|
|
|
from bika.lims import api |
|
22
|
|
|
from bika.lims.interfaces import IClient |
|
23
|
|
|
from bika.lims.interfaces import IContact |
|
24
|
|
|
from bika.lims.interfaces import ILabContact |
|
25
|
|
|
from bika.lims.interfaces import ISupplierContact |
|
26
|
|
|
from plone.indexer import indexer |
|
27
|
|
|
from senaite.core.interfaces.catalog import IContactCatalog |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
@indexer(IContact, IContactCatalog) |
|
31
|
|
|
@indexer(ILabContact, IContactCatalog) |
|
32
|
|
|
@indexer(ISupplierContact, IContactCatalog) |
|
33
|
|
|
def sortable_title(instance): |
|
34
|
|
|
return instance.getFullname().lower() |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
@indexer(IContact, IContactCatalog) |
|
38
|
|
|
@indexer(ILabContact, IContactCatalog) |
|
39
|
|
|
@indexer(ISupplierContact, IContactCatalog) |
|
40
|
|
|
def getParentUID(instance): |
|
41
|
|
|
parent = instance.aq_parent |
|
42
|
|
|
if not IClient.providedBy(parent): |
|
43
|
|
|
return None |
|
44
|
|
|
return parent.UID() |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
@indexer(IContact, IContactCatalog) |
|
48
|
|
|
@indexer(ILabContact, IContactCatalog) |
|
49
|
|
|
@indexer(ISupplierContact, IContactCatalog) |
|
50
|
|
|
def listing_searchable_text(instance): |
|
51
|
|
|
"""Extract search tokens for ZC text index |
|
52
|
|
|
""" |
|
53
|
|
|
|
|
54
|
|
|
tokens = [ |
|
55
|
|
|
instance.getBusinessPhone(), |
|
56
|
|
|
instance.getCity(), |
|
57
|
|
|
instance.getCountry(), |
|
58
|
|
|
instance.getEmailAddress(), |
|
59
|
|
|
instance.getFullname(), |
|
60
|
|
|
instance.getHomePhone(), |
|
61
|
|
|
instance.getJobTitle(), |
|
62
|
|
|
instance.getMobilePhone(), |
|
63
|
|
|
instance.getUsername(), |
|
64
|
|
|
] |
|
65
|
|
|
|
|
66
|
|
|
department = instance.getDepartment() # part of person base class |
|
67
|
|
|
if isinstance(department, list): # override in labcontact |
|
68
|
|
|
department_titles = map(api.get_title, department) |
|
69
|
|
|
tokens.extend(department_titles) |
|
70
|
|
|
elif api.is_string(department): |
|
71
|
|
|
tokens.append(department) |
|
72
|
|
|
|
|
73
|
|
|
# remove duplicates and filter out emtpies |
|
74
|
|
|
tokens = filter(None, set(tokens)) |
|
75
|
|
|
|
|
76
|
|
|
# return a single unicode string with all the concatenated tokens |
|
77
|
|
|
return u" ".join(map(api.safe_unicode, tokens)) |
|
78
|
|
|
|