Exemple #1
0
 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 _renderCustomizedViewlet(self, viewlethash, templateName):
     """ Rerender the viewlets to show the new code """
     # Unhash the viewlet info. Pull out what we need.
     unhashedInfo = unhashViewletInfo(viewlethash)
     managerName = unhashedInfo['managerName']
     viewletName = unhashedInfo['viewletName']
     
     ksscore = self.getCommandSet('core')
     
     # Find the viewletmangager instance, tell it to update its rendering, and replace the contents of the selected div with that new html
     # We can't do this with a refreshViewlet or refreshProvider because then we lose the <tal:viewletmanager> and <tal:viewlet> blocks.
     # selector = ksscore.getCssSelector('.kssattr-viewletmanagername-' + managerName.replace('.', '-'))
     viewletManager = findViewletManager(self, managerName)
     viewletManager.update()
     
     vlt = ksscore.getCssSelector('.kssattr-viewlethash-%s' % viewlethash)
     # Get the viewlet.
     # TODO: Is there a better way to do this?
     for viewlet in viewletManager.viewlets:
         if hasattr(viewlet, 'template') and viewlet.template.__name__ == templateName:
             # Turn on the debug flags for the viewlet's request, so that we have our tal: content
             self._turnOnTalRenderingForObjectsRequest(viewlet)
             ksscore.replaceInnerHTML(vlt, viewlet.render())
             break
     return self.render()
 def _redrawViewletManager(self, managerName):
     # Get the viewlet manager, update, and rerender it
     # We can't do this with a refreshProvider call because then we lose the <tal:viewletmanager> block.\
     viewletManager = findViewletManager(self, managerName)
     viewletManager.update()
     
     # Apply all of the bits we need for inline tal
     self._turnOnTalRenderingForObjectsRequest(viewletManager)
     
     # Update the display
     ksscore = self.getCommandSet('core')
     selector = ksscore.getCssSelector('.kssattr-viewletmanagername-' + managerName.replace('.', '-'))
     ksscore.replaceInnerHTML(selector, viewletManager.render())
     return self.render()
 def moveViewletByDelta(self, viewlethash, delta):
     """ Move the viewlet within its viewlet manager """
     logger.debug("in moveViewletByDelta")
     
     # Grab the information we need from the viewlet hash
     unhashedInfo = unhashViewletInfo(viewlethash)
     managerName = unhashedInfo['managerName']
     viewletName = unhashedInfo['viewletName']
     
     # Make sure delta is an integer, KSS apparently passes it in as a string.
     logger.debug("Converting %s to an integer" % delta)
     delta = int(delta)
     logger.debug("Moving viewlet by %s" % delta)
     
     # Get the viewletmanager object
     viewletManager = findViewletManager(self, managerName)
     
     # Get the order of the viewlets managed by this viewlet manager
     viewletManager.update()
     storage = getUtility(IViewletSettingsStorage)
     skinname = self.context.getCurrentSkinName()
     order = list(storage.getOrder(managerName, skinname))
     
     viewlet_index = order.index(viewletName)
     
     # Move the viewlet to its new position
     newpos = max(0, viewlet_index + delta) and min(viewlet_index + delta, len(order))
     del order[viewlet_index]
     order.insert(newpos, viewletName)
     storage = getUtility(IViewletSettingsStorage)
     storage.setOrder(managerName, skinname, order)
     
     # Update the page display
     self._redrawViewletManager(managerName)
     
     zope = self.getCommandSet('zope')
     zope.refreshViewlet('#glowormPanelNavTree', 'gloworm.glowormPanel', 'glowormPanelNavTree')
     # Make sure the manager is still shown in the nav tree after reloading
     ksscore = self.getCommandSet('core')
     self.highlightInNavTree(ksscore.getCssSelector('#glowormPanelNavTree .kssattr-forviewletmanager-%s' % managerName.replace('.', '-')))
     
     # Update the viewlet listing in the GloWorm panel
     self.inspectViewletManager(managerName)
     
     return self.render()
 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()