Пример #1
0
 def is_in_client(self):
     """Returns whether the current context is from inside a client
     """
     if self._is_in_client is None:
         client = get_client_from_chain(self.context)
         self._is_in_client = client and True or False
     return self._is_in_client
Пример #2
0
def resolve_client(obj, field_name=None):
    """Tries to resolve the client for the given obj
    """
    if not field_name:
        field_name = "Client"
        if IPatient.providedBy(obj) or IDoctor.providedBy(obj):
            field_name = "PrimaryReferrer"

    # Try to get the client directly from the field
    client = obj.getField(field_name).get(obj)
    if client and IClient.providedBy(client):
        return client

    # Maybe the object is being created
    if obj.isTemporary():
        parent = obj.getFolderWhenPortalFactory()
    else:
        parent = api.get_parent(obj)

    # Get the Client from the acquisition chain, if any
    return get_client_from_chain(parent)
Пример #3
0
 def get_client(self):
     """Returns the client this context is from, if any
     """
     return get_client_from_chain(self.context)
Пример #4
0
    def get_raw_query(self):
        """Returns the raw query to use for current search, based on the
        base query + update query
        """
        query = super(ClientAwareReferenceWidgetAdapter, self).get_raw_query()
        logger.info("===============================================")
        logger.info("Custom client-aware reference widget vocabulary")
        logger.info(repr(query))

        # Get the portal types from the query
        portal_type = self.get_portal_type(query)
        if not portal_type:
            # Don't know the type we are searching for, do nothing
            return query

        if portal_type not in self.client_aware_types:
            # The portal type is not client aware, do nothing
            return query

        # Try to resolve the client from the query
        client = self.get_client_from_query(query, purge=True)

        # Resolve the client from the context chain
        client = get_client_from_chain(self.context) or client

        # Resolve the criteria for filtering
        criteria = {}

        if portal_type in self.widely_shared_types:

            # The portal type can be shared widely (e.g. Sample Type)
            criteria = self.resolve_query(portal_type, client, True)

        elif portal_type in self.internally_shared_types:

            # The portal type can be shared among internal clients (e.g Batch)
            criteria = resolve_query_for_shareable(portal_type, client)

        elif portal_type == "Client":

            # Special case, when the item to look for is a Client
            context_portal_type = api.get_portal_type(self.context)
            if context_portal_type in self.internally_shared_types:

                # Current context can be shared internally (e.g. Batch)
                if client:
                    # Display only the current Client in searches
                    criteria = self.resolve_query(portal_type, client, False)

                else:
                    # Display all internal clients
                    internal_clients = api.get_portal().internal_clients
                    criteria = {
                        "path": {
                            "query": api.get_path(internal_clients),
                            "depth": 1
                        }
                    }

            else:
                # Display current client only (if client != None) or all them
                criteria = self.resolve_query(portal_type, client, False)

        elif client:
            # Portal type is not shareable in any way (e.g Contact)
            criteria = self.resolve_query(portal_type, client, False)

        query.update(criteria)
        logger.info(repr(query))
        logger.info("===============================================")
        return query