Beispiel #1
0
    def __call__(self, query='', dataRoot='devices'):
        """
        @param query: A glob by which to filter device names
        @type query: str
        @return: A JSON representation of a list of ids
        @rtype: "['id1', 'id2', 'id3']"
        """
        if dataRoot != 'devices':
            import exceptions
            raise exceptions.ValueError("dataRoot should only be 'devices'")

        query_scope = self.context.dmd.Devices
        query = MatchGlob('name', query.rstrip('*') + '*')
        if isinstance(self.context, DeviceOrganizer):
            query_scope = self.context
        catalog = IModelCatalogTool(query_scope).devices
        brains = catalog.search(query=query, fields=['name'])

        return sorted((b.name for b in brains), key=lambda x: x.lower())
Beispiel #2
0
    def __call__(self, query='', dataRoot='devices'):
        """
        @param query: A glob by which to filter device names
        @type query: str
        @return: A JSON representation of a list of ids
        @rtype: "['id1', 'id2', 'id3']"
        """
        if dataRoot != 'devices':
            import exceptions
            raise exceptions.ValueError("dataRoot should only be 'devices'")
        catalog = getToolByName(self.context.dmd.Devices,
            self.context.dmd.Devices.default_catalog)
        query = MatchGlob('titleOrId', query.rstrip('*') + '*')
        if isinstance(self.context, DeviceOrganizer):
            query = query & Eq('path', "/".join(self.context.getPhysicalPath()))
        brains = catalog.evalAdvancedQuery(query)

        # TODO: Add titleOrId to the catalog's metadata.
        return  sorted((b.getObject().titleOrId() for b in brains),
                        key=lambda x: x.lower())
    def __call__(self, query='', dataRoot='devices'):
        """
        @param query: A glob by which to filter device names
        @type query: str
        @return: A JSON representation of a list of ids
        @rtype: "['id1', 'id2', 'id3']"
        """
        if dataRoot != 'devices':
            import exceptions
            raise exceptions.ValueError("dataRoot should only be 'devices'")

        query_scope = self.context.dmd.Devices
        query = MatchGlob('name', query.rstrip('*') + '*')
        if isinstance(self.context, DeviceOrganizer):
            query_scope = self.context
        catalog = IModelCatalogTool(query_scope).devices
        brains = catalog.search(query=query, fields=['name'])

        return  sorted((b.name for b in brains),
                        key=lambda x: x.lower())
Beispiel #4
0
    def __call__(self, query='', dataRoot='devices'):
        """
        @param query: A glob by which to filter device names
        @type query: str
        @return: A JSON representation of a list of ids
        @rtype: "['id1', 'id2', 'id3']"
        """
        if dataRoot != 'devices':
            import exceptions
            raise exceptions.ValueError("dataRoot should only be 'devices'")
        catalog = getToolByName(self.context.dmd.Devices,
            self.context.dmd.Devices.default_catalog)
        query = MatchGlob('titleOrId', query.rstrip('*') + '*')
        if isinstance(self.context, DeviceOrganizer):
            query = query & Eq('path', "/".join(self.context.getPhysicalPath()))
        brains = catalog.evalAdvancedQuery(query)

        # TODO: Add titleOrId to the catalog's metadata.
        return  sorted((b.getObject().titleOrId() for b in brains),
                        key=lambda x: x.lower())