def get_brain_info(brain): """Extract the brain info """ icon = api.get_icon(brain) # avoid 404 errors with these guys if "document_icon.gif" in icon: icon = "" id = api.get_id(brain) url = api.get_url(brain) title = api.get_title(brain) description = api.get_description(brain) parent = api.get_parent(brain) parent_title = api.get_title(parent) parent_url = api.get_url(parent) return { "id": id, "title": title, "title_or_id": title or id, "description": description, "url": url, "parent_title": parent_title, "parent_url": parent_url, "icon": icon, }
def spotlight_search_route(context, request): """The spotlight search route """ catalogs = [ "portal_catalog", "bika_setup_catalog", "bika_catalog", # "bika_analysis_catalog" ] search_results = [] for catalog in catalogs: search_results.extend(search(catalog=catalog)) def get_state(brain): state = getattr(brain, "review_state", "") if not isinstance(state, basestring): return "" return state items = [] for brain in search_results: icon = api.get_icon(brain) # avoid 404 errors with these guys if "document_icon.gif" in icon: icon = "" id = api.get_id(brain) title = api.get_title(brain) items.append({ "id": id, "title": title, "title_or_id": title or id, "description": api.get_description(brain), "uid": api.get_uid(brain), "path": api.get_path(brain), "url": api.get_url(brain), "state": get_state(brain), "icon": icon, }) return { "count": len(items), "items": items, }
def get_icon_url(self, brain): """Returns the (big) icon URL for the given catalog brain """ icon_url = api.get_icon(brain, html_tag=False) url, icon = icon_url.rsplit("/", 1) relative_url = url.lstrip(self.portal.absolute_url()) name, ext = os.path.splitext(icon) # big icons endwith _big if not name.endswith("_big"): icon = "{}_big{}".format(name, ext) icon_big_url = "/".join([relative_url, icon]) # fall back to a default icon if the looked up icon does not exist if self.context.restrictedTraverse(icon_big_url, None) is None: icon_big_url = "++resource++senaite.lims.images/gears.png" return icon_big_url