Passed
Pull Request — 2.x (#1872)
by Ramon
04:28
created

senaite.core.catalog.indexer.generic   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 23
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A listing_searchable_text() 0 8 1
A sortable_title() 0 8 2
A is_active() 0 6 1
1
# -*- coding: utf-8 -*-
2
3
from bika.lims import api
4
from plone.indexer import indexer
5
from Products.CMFCore.interfaces import IContentish
6
from Products.CMFPlone.CatalogTool import \
7
    sortable_title as plone_sortable_title
8
from Products.CMFPlone.utils import safe_callable
9
from senaite.core.catalog import SENAITE_CATALOG
10
from senaite.core.interfaces import ISenaiteCatalog
11
from senaite.core.catalog.utils import get_searchable_text_tokens
12
13
14
@indexer(IContentish)
15
def is_active(instance):
16
    """Returns False if the status of the instance is 'cancelled' or 'inactive'.
17
    Otherwise returns True
18
    """
19
    return api.is_active(instance)
20
21
22
@indexer(IContentish)
23
def sortable_title(instance):
24
    """Uses the default Plone sortable_text index lower-case
25
    """
26
    title = plone_sortable_title(instance)
27
    if safe_callable(title):
28
        title = title()
29
    return title.lower()
30
31
32
@indexer(IContentish, ISenaiteCatalog)
33
def listing_searchable_text(instance):
34
    """ Retrieves all the values of metadata columns in the catalog for
35
    wildcard searches
36
    :return: all metadata values joined in a string
37
    """
38
    tokens = get_searchable_text_tokens(instance, SENAITE_CATALOG)
39
    return u" ".join(tokens)
40