def asyncGetTree(self, id=None, additionalKeys=()): """ Server side method for asynchronous tree calls. Retrieves the immediate children of the node specified by "id" NOTE: our convention on the UI side is if we are asking for the root node then return the root and its children otherwise just return the children @type id: string @param id: The uid of the node we are getting the children for @rtype: [dictionary] @return: Object representing the immediate children """ showEventSeverityIcons = self.context.dmd.UserInterfaceSettings.getInterfaceSettings( ).get('showEventSeverityIcons') facade = self._getFacade() currentNode = facade.getTree(id) # we want every tree property except the "children" one keys = ('id', 'path', 'uid', 'iconCls', 'text', 'hidden', 'leaf') + additionalKeys # load the severities in one request childNodes = list(currentNode.children) if showEventSeverityIcons: uuids = [n.uuid for n in childNodes if n.uuid] zep = Zuul.getFacade('zep', self.context.dmd) if uuids: severities = zep.getWorstSeverity(uuids) for child in childNodes: if child.uuid: child.setSeverity( zep.getSeverityName(severities.get(child.uuid, 0)).lower()) children = [] # explicitly marshall the children for child in childNodes: childData = Marshaller(child).marshal(keys) children.append(childData) children.sort(key=lambda e: (e['leaf'], e['uid'].lower())) obj = currentNode._object._unrestrictedGetObject() # check to see if we are asking for the root primaryId = obj.getDmdRoot(obj.dmdRootName).getPrimaryId() if id == primaryId: root = Marshaller(currentNode).marshal(keys) root['children'] = children return [root] return children
def _marshalPath(self, contextUid, newId=None, localKeys=None): tokens = contextUid.split('/') if newId: tokens.append(newId) paths = [] # ["", "zport", "dmd", "Reports", <new node or an ancestor, at 4>, ...] for x in range(4, len(tokens) + 1): paths.append('/'.join(tokens[:x])) nodes = [self._getFacade().getTree(id) for id in paths] return [Marshaller(node).marshal(localKeys) for node in nodes]
def _marshalPath(self, contextUid, newId=None, localKeys=None): # ensure all uids have cse_virtual_root prefix contextUid = getUtility(IVirtualRoot).ensure_virtual_root(contextUid) tokens = contextUid.split('/') if newId: tokens.append(newId) paths = [] # ["", "cse_virtual_root", "zport", "dmd", "Reports", <new node or an ancestor, at 5>, ...] for x in range(5, len(tokens) + 1): paths.append('/'.join(tokens[:x])) nodes = [self._getFacade().getTree(id) for id in paths] return [Marshaller(node).marshal(localKeys) for node in nodes]
def asyncGetTree(self, id=None, additionalKeys=()): """ Server side method for asynchronous tree calls. Retrieves the immediate children of the node specified by "id" NOTE: our convention on the UI side is if we are asking for the root node then return the root and its children otherwise just return the children @type id: string @param id: The uid of the node we are getting the children for @rtype: [dictionary] @return: Object representing the immediate children """ showEventSeverityIcons = self.context.dmd.UserInterfaceSettings.getInterfaceSettings( ).get('showEventSeverityIcons') facade = self._getFacade() currentNode = facade.getTree(id) # we want every tree property except the "children" one keys = ('id', 'path', 'uid', 'iconCls', 'text', 'hidden', 'leaf') + additionalKeys # load the severities in one request childNodes = list(currentNode.children) if showEventSeverityIcons: uuids = [n.uuid for n in childNodes if n.uuid] zep = Zuul.getFacade('zep', self.context.dmd) if uuids: severities = zep.getWorstSeverity(uuids) for child in childNodes: if child.uuid: child.setSeverity( zep.getSeverityName(severities.get(child.uuid, 0)).lower()) children = [] # explicitly marshall the children for child in childNodes: childData = Marshaller(child).marshal(keys) # set children so that there is not an expanding # icon next to this child # see if there are any subtypes so we can show or not show the # expanding icon without serializing all the children. # Note that this is a performance optimization see ZEN-15857 organizer = child._get_object() # this looks at the children's type without waking them up hasChildren = any((o['meta_type'] for o in organizer._objects if o['meta_type'] == organizer.meta_type)) # reports have a different meta_type for the child organizers if "report" not in organizer.meta_type.lower() and not hasChildren: childData['children'] = [] children.append(childData) children.sort(key=lambda e: (e['leaf'], e['uid'].lower())) obj = currentNode._object._unrestrictedGetObject() # check to see if we are asking for the root primaryId = obj.getDmdRoot(obj.dmdRootName).getPrimaryId() if currentNode.uid == primaryId: root = Marshaller(currentNode).marshal(keys) root['children'] = children return [root] return children