| Total Complexity | 4 | 
| Total Lines | 40 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 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 |