Exemplo n.º 1
0
def get_search_results(portal_type=None, uid=None, **kw):
    """Search the catalog and return the results

    :returns: Catalog search results
    :rtype: iterable
    """

    # If we have an UID, return the object immediately
    if uid is not None:
        logger.info("UID '%s' found, returning the object immediately" % uid)
        return u.to_list(get_object_by_uid(uid))

    # allow to search search for the Plone Site with portal_type
    include_portal = False
    if u.to_string(portal_type) == "Plone Site":
        include_portal = True

    # The request may contain a list of portal_types, e.g.
    # `?portal_type=Document&portal_type=Plone Site`
    if "Plone Site" in u.to_list(req.get("portal_type")):
        include_portal = True

    # Build and execute a catalog query
    results = search(portal_type=portal_type, uid=uid, **kw)

    if include_portal:
        results = list(results) + u.to_list(get_portal())

    return results
Exemplo n.º 2
0
def setup_left_portlet_column(portal):
    """Setup left column portlets
    """
    logger.info("********** Setup left portlet columns")
    mapping = portal.restrictedTraverse('++contextportlets++plone.leftcolumn')

    # delete all portlets on the left
    for key in mapping.keys():
        del mapping[key]

    # create a new navigation portlet
    navigation_portlet = component.getUtility(IPortletType,
                                              name='portlets.Navigation')
    addview = mapping.restrictedTraverse('+/' + navigation_portlet.addview)
    data = dict(name=u"Navigation",
                root=None,
                currentFolderOnly=False,
                includeTop=False,
                topLevel=0,
                bottomLevel=0)
    addview.createAndAdd(data)

    # make the navigation portlet the first portlet
    order = list(mapping.keys())
    order.insert(0, order.pop())
    logger.info("********** Changed portlet order from %s to %s" %
                (repr(list(mapping.keys())), repr(order)))
    mapping.updateOrder(order)
Exemplo n.º 3
0
def setup_right_portlet_column(portal):
    """Setup right column portlets
    """
    logger.info("********** Setup right portlet columns")
    mapping = portal.restrictedTraverse('++contextportlets++plone.rightcolumn')

    for key in ['news', 'events', 'Calendar']:
        if key in mapping:
            del mapping[key]
Exemplo n.º 4
0
def setup_handler(context):
    """Generic setup handler
    """

    if context.readDataFile('senaite.lims.txt') is None:
        return

    logger.info("SENAITE setup handler [BEGIN]")
    portal = context.getSite()  # noqa
    logger.info("SENAITE setup handler [DONE]")
Exemplo n.º 5
0
    def search(self, query):
        """search the catalog
        """
        logger.info("Catalog query={}".format(query))

        # Support to set the catalog as a request parameter
        catalogs = _.to_list(req.get("catalog", None))
        if catalogs:
            return bikaapi.search(query, catalog=catalogs)
        # Delegate to the search API of Bika LIMS
        return bikaapi.search(query)
Exemplo n.º 6
0
def setup_html_filter(portal):
    """Setup HTML filtering for resultsinterpretations
    """
    logger.info("*** Setup HTML Filter ***")
    # bypass the broken API from portal_transforms
    adapter = IFilterSchema(portal)
    style_whitelist = adapter.style_whitelist
    for style in ALLOWED_STYLES:
        logger.info("Allow style '{}'".format(style))
        if style not in style_whitelist:
            style_whitelist.append(style)
    adapter.style_whitelist = style_whitelist
Exemplo n.º 7
0
def post_uninstall(portal_setup):
    """Runs after the last import step of the *uninstall* profile

    This handler is registered as a *post_handler* in the generic setup profile

    :param portal_setup: SetupTool
    """
    logger.info("SENAITE LIMS uninstall handler [BEGIN]")

    # https://docs.plone.org/develop/addons/components/genericsetup.html#custom-installer-code-setuphandlers-py
    profile_id = "profile-senaite.lims:uninstall"
    context = portal_setup._getImportContext(profile_id)
    portal = context.getSite()  # noqa

    logger.info("SENAITE LIMS uninstall handler [DONE]")
Exemplo n.º 8
0
def setupHandler(context):
    """SENAITE setup handler
    """

    if context.readDataFile('senaite.lims.txt') is None:
        return

    logger.info("SENAITE setup handler [BEGIN]")

    portal = context.getSite()  # noqa

    # Run Installers
    setup_left_portlet_column(portal)
    setup_right_portlet_column(portal)

    logger.info("SENAITE setup handler [DONE]")
Exemplo n.º 9
0
    def make_query(self, **kw):
        """create a query suitable for the catalog
        """
        query = kw.pop("query", {})

        query.update(self.get_request_query())
        query.update(self.get_custom_query())
        query.update(self.get_keyword_query(**kw))

        sort_on, sort_order = self.get_sort_spec()
        if sort_on and "sort_on" not in query:
            query.update({"sort_on": sort_on})
        if sort_order and "sort_order" not in query:
            query.update({"sort_order": sort_order})

        logger.info("make_query:: query={} | catalog={}".format(
            query, self.catalog))

        return query
Exemplo n.º 10
0
def pre_install(portal_setup):
    """Runs berfore the first import step of the *default* profile

    This handler is registered as a *pre_handler* in the generic setup profile

    :param portal_setup: SetupTool
    """
    logger.info("SENAITE LIMS pre-install handler [BEGIN]")

    # https://docs.plone.org/develop/addons/components/genericsetup.html#custom-installer-code-setuphandlers-py
    profile_id = "profile-senaite.lims:default"
    context = portal_setup._getImportContext(profile_id)
    portal = context.getSite()  # noqa

    # Only install the core once!
    qi = portal.portal_quickinstaller
    if not qi.isProductInstalled("bika.lims"):
        portal_setup.runAllImportStepsFromProfile("profile-bika.lims:default")

    logger.info("SENAITE LIMS pre-install handler [DONE]")
Exemplo n.º 11
0
    def get_icon_for(self, brain_or_object):
        """Get the navigation portlet icon for the brain or object

        The cache key ensures that the lookup is done only once per domain name
        """
        portal_types = api.get_tool("portal_types")
        fti = portal_types.getTypeInfo(api.get_portal_type(brain_or_object))
        icon = fti.getIcon()
        if not icon:
            return ""
        # Always try to get the big icon for high-res displays
        icon_big = icon.replace(".png", "_big.png")
        # fall back to a default icon if the looked up icon does not exist
        if self.context.restrictedTraverse(icon_big, None) is None:
            icon_big = None
        portal_url = api.get_url(api.get_portal())
        title = api.get_title(brain_or_object)
        html_tag = "<img title='{}' src='{}/{}' width='16' />".format(
            title, portal_url, icon_big or icon)
        logger.info("Generated Icon Tag for {}: {}".format(
            api.get_path(brain_or_object), html_tag))
        return html_tag
Exemplo n.º 12
0
# -*- coding: utf-8 -*-

import pkgutil

from senaite.lims import logger
from senaite.lims.jsonapi.v1 import routes
from senaite.lims.jsonapi import add_route as add_senaite_route

__version__ = 1
__date__ = "2017-08-08"

BASE_URL = "/senaite/v1"


def add_route(route, endpoint=None, **kw):
    """Add a new JSON API route
    """

    # ensure correct amout of slashes
    def apiurl(route):
        return '/'.join(s.strip('/') for s in ["", BASE_URL, route])

    return add_senaite_route(apiurl(route), endpoint, **kw)


prefix = routes.__name__ + "."
for importer, modname, ispkg in pkgutil.iter_modules(routes.__path__, prefix):
    module = __import__(modname, fromlist="dummy")
    logger.info("INITIALIZED SENAITE JSONAPI V1 ROUTE ---> %s" %
                module.__name__)