def getChildViewletManagers(node): """ Find all viewletmanagers within this node """ all = node.findAll('tal:viewletmanager') stripped = [] self.outstr += "<ol class='viewletmanager-tree'>" for v in all: if not(stripped and v.findParent('tal:viewletmanager') and stripped[-1] in v.findParents('tal:viewletmanager')): rawname = v.attrs[0][1][27:] # 27 = len('kssattr-viewletmanagername-') # Break off any extra class names # TODO We should really be safe and check for classes before and after. rawname = rawname.split(' ',1)[0] name = rawname.replace('-','.') # Get the viewletmanager object managerObj = findViewletManager(self, name) if managerObj and not IAmIgnoredByGloworm.providedBy(managerObj): self.outstr += "<li><a href='#' title='Viewlet Manager %s' class='inspectViewletManager kssattr-forviewletmanager-%s'>%s</a>" % (name, name.replace('.', '-'), name) # Look up the viewlets attached to this viewlet manager. # We do it this way because calling viewletManager.viewlets won't see the hidden viewlets... containedViewlets = getAdapters((self.context, self.request, managerObj.__parent__, managerObj),IViewlet) containedViewlets = managerObj.sort([vl for vl in containedViewlets]) stripped.append(v) getChildViewlets(v, containedViewlets) self.outstr += "</li>" self.outstr += "</ol>" return stripped
def getChildViewlets(node, allViewlets=[]): """ Find all viewlets within this node """ all = node.findAll('tal:viewlet') stripped = [] self.outstr += "<ol class='viewlet-tree'>" def writeHiddenViewlet(viewlet): """ Create a list item HTML bit for a hidden viewlet """ name = viewlet[0] managerObj = viewlet[1].manager viewletHash = hashViewletInfo(name, managerObj.__name__, getProvidedForViewlet(name, managerObj)) return "<li><a href='#' title='Hidden viewlet %s' class='viewletMoreInfo hiddenViewlet kssattr-forviewlet-%s'>%s</a></li>" % (name, viewletHash, name) for v in all: if not(stripped and v.findParent('tal:viewlet') and stripped[-1] in v.findParents('tal:viewlet')): viewletHash = v.attrs[0][1][20:] # 20 = len('kssattr-viewlethash-') # Break off any extra class names # TODO We should really be safe and check for classes before and after. viewletHash = viewletHash.split(' ',1)[0] reg = findTemplateViewRegistrationFromHash(viewletHash) if reg: while allViewlets and reg.name != allViewlets[0][0]: self.outstr += writeHiddenViewlet(allViewlets[0]) allViewlets.pop(0) if not IAmIgnoredByGloworm.providedBy(allViewlets[0][1]): self.outstr += "<li><a href='#' title='Visible viewlet %s' class='viewletMoreInfo kssattr-forviewlet-%s'>%s</a>" % (reg.name, viewletHash, reg.name) stripped.append(v) getChildViewletManagers(v) self.outstr += "</li>" allViewlets.pop(0) # Remove the current viewlet from the allViewlets list # Collect any remaining hidden viewletss if allViewlets: for vlt in allViewlets: self.outstr += writeHiddenViewlet(vlt) self.outstr += "</ol>" return stripped
def inspectViewletManager(self, managerName): """ Display information about a particular viewlet manager """ logger.debug("in inspectViewletManager") # Get the viewletmanager object managerName = managerName.replace('-', '.') viewletManager = findViewletManager(self, managerName) # Gather information for the viewlet hashes managerInterface = list(providedBy(viewletManager).flattened())[0] # Look up the viewlets attached to this viewlet manager. # We do it this way because calling viewletManager.viewlets won't see the hidden viewlets... viewlets = getAdapters((self.context, self.request, viewletManager.__parent__, viewletManager),IViewlet) # Get the names of the hidden viewlets storage = getUtility(IViewletSettingsStorage) hidden = frozenset(storage.getHidden(managerName, self.context.getCurrentSkinName())) # Generate the output sortedViewlets = viewletManager.sort(viewlets) containedViewlets = [] for viewletname, viewletObj in sortedViewlets: containedViewlet = {} if not IAmIgnoredByGloworm.providedBy(viewletObj): # generate viewlet hashes... # TODO factor this up. # Get the "provided" interfaces for this viewlet manager. # TODO: Do this lookup properly. regs = [regs for regs in getGlobalSiteManager().registeredAdapters() if regs.name == viewletname and regs.required[-1].isOrExtends(managerInterface)] if regs: reg = regs[0] provided = ','.join([a.__identifier__ for a in reg.required]) # logger.debug("%s - provided: %s" % (viewletName, provided)) hashedInfo = binascii.b2a_hex("%s\n%s\n%s" % (viewletname, managerName, provided)) else: hashedInfo = "" logger.debug("Unable to create hash for %s" % viewletname) # Give the viewlet a class name depending on the visibility classname = viewletname in hidden and 'hiddenViewlet' or 'visibleViewlet' logger.debug(classname) containedViewlet['className'] = classname containedViewlet['hashedInfo'] = hashedInfo containedViewlet['name'] = viewletname containedViewlets.append(containedViewlet) # Determine whether the contained viewlets can be sorted. skinname = self.context.getCurrentSkinName() canOrder = bool(storage.getOrder(managerName, skinname)) template = ViewPageTemplateFile('panel_inspect_viewlet_manager.pt') # Wrap it so that Zope knows in what context it's being called # Otherwise, we get an "AttributeError: 'str' object has no attribute 'other'" error template = BoundPageTemplate(template, self) out = template(managerName = managerName, safeManagerName = managerName.replace('.', '-'), containedViewlets = containedViewlets, canOrder = canOrder ) # Dump the output to the output panel self.updatePanelBodyContent(out) # Highlight the element ksscore = self.getCommandSet('core') self.highlightElement(ksscore.getCssSelector('.kssattr-viewletmanagername-%s' % managerName.replace('.', '-'))) # And in the nav tree (Should this be here or in the nav tree viewlet code?) self.highlightInNavTree(ksscore.getCssSelector('#glowormPanelNavTree .kssattr-forviewletmanager-%s' % managerName.replace('.', '-'))) return self.render()