示例#1
0
 def showMoveViewletForm(self, viewlethash):
     """ Show the form for moving a viewlet between managers. """
     
     unhashedViewletInfo = unhashViewletInfo(viewlethash)
     reg = findTemplateViewRegistrationFromHash(viewlethash)
     viewRegistrationInfo = list(registration.templateViewRegistrationInfos([reg]))[0]
     
     managerName = unhashedViewletInfo['managerName']
     managerNames = self._getAllViewletManagerNames()
     managerNames.sort()
     # Remove the viewlet's current viewlet manager and the gloworm panel from the choices.
     managerNames.remove(unhashedViewletInfo['managerName'])
     managerNames.remove('gloworm.glowormPanel')
     
     template = ViewPageTemplateFile('panel_move_viewlet.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(viewlethash=viewlethash,
                    viewletName = unhashedViewletInfo['viewletName'],
                    managerNames = managerNames)
     # Dump the output to the inspector panel
     self.updatePanelBodyContent(out)
     
     return self.render()
示例#2
0
 def saveViewletTemplate(self, viewlethash, newContent):
     """ Update portal_view_customizations with the new version of the template. """
     logger.debug("in saveViewletTemplate")
     
     # Hide the error message
     self.hideTemplateErrorMessage()
     
     # Unhash the viewlet info. Pull out what we need.
     unhashedInfo = unhashViewletInfo(viewlethash)
     viewletName = unhashedInfo['viewletName']
     # Find the template in portal_view_customizations, save the new version
     container = queryUtility(IViewTemplateContainer)
     
     reg = findTemplateViewRegistrationFromHash(viewlethash)
     templateName = registration.generateIdFromRegistration(reg)
     
     try:
         container[templateName].write(newContent)
         result = self._renderCustomizedViewlet(viewlethash, templateName)
     except PTRuntimeError:
         message = container[templateName].pt_errors(self)[1]
         transaction.abort()
         return self.showTemplateErrorMessage(message)
     except TraversalError, e:
         transaction.abort()
         viewlet, err = e
         return self.showTemplateErrorMessage("TraversalError: %s" % err)
示例#3
0
 def inspectViewlet(self, viewlethash):
     """ Display detailed information about a particular viewlet. """
     logger.debug("in inspectViewlet")
     
     # Unhash the viewlet info
     unhashedViewletInfo = unhashViewletInfo(viewlethash)
     # Get the registration information for this viewlet
     reg = findTemplateViewRegistrationFromHash(viewlethash)
     
     viewName = unhashedViewletInfo['viewletName']
     managerName = unhashedViewletInfo['managerName']
     cls = registration.getViewClassFromRegistration(reg)
     className = "%s.%s" % (cls.__module__, cls.__name__)
     try:
         viewRegistrationInfo = list(registration.templateViewRegistrationInfos([reg]))[0]
     except IndexError:
         # For some reason, there's no registration with portal_view_cusomtizations,
         # this appears to happen when there's no template defined for the viewlet and it instead
         # uses a "render" method.
         customizationExists = False
         customizationAllowed = False
         templatePath = ""
     else:
         template = viewRegistrationInfo['zptfile']
         templatePath = registration.generateIdFromRegistration(reg)
         container = queryUtility(IViewTemplateContainer)
         customizationExists = templatePath in container
         customizationAllowed = True
     
     # Get the names of the hidden viewlets
     storage = getUtility(IViewletSettingsStorage)
     hiddenViewlets = frozenset(storage.getHidden(managerName, self.context.getCurrentSkinName()))
     isVisible = viewName not in hiddenViewlets
     
     template = ViewPageTemplateFile('panel_inspect_viewlet.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(viewName = viewName,
                    managerName = managerName,
                    template = template,
                    className = className,
                    templatePath = templatePath,
                    customizationExists = customizationExists,
                    customizationAllowed = customizationAllowed,
                    visible = isVisible,
                    viewletHash = viewlethash)
     
     # Dump the output to the output panel
     self.updatePanelBodyContent(out)
     
     # Highlight this element
     ksscore = self.getCommandSet('core')
     self.highlightElement(ksscore.getCssSelector('.kssattr-viewlethash-%s' % viewlethash))
     
     # And in the nav tree (Should this be here or in the nav tree viewlet code?)
     self.highlightInNavTree(ksscore.getCssSelector('#glowormPanelNavTree .kssattr-forviewlet-%s' % viewlethash))
     
     return self.render()
示例#4
0
 def discardViewletCustomizations(self, viewlethash):
     """ Remove the customized template for a particular viewlet """
     # Unhash the viewlet info
     unhashedViewletInfo = unhashViewletInfo(viewlethash)
     
     # Get the viewlet's registration information from portal_view_customizations
     container = queryUtility(IViewTemplateContainer)
     reg = findTemplateViewRegistrationFromHash(viewlethash)
     templateName = registration.generateIdFromRegistration(reg)
     
     container.manage_delObjects([templateName])
     self._redrawViewletManager(unhashedViewletInfo['managerName'])
     return self.inspectViewlet(viewlethash)
示例#5
0
 def moveViewletToViewletManager(self, viewlethash, toManagerName):
     """ Register the viewlet as belonging to the specified viewlet manager """
     # Unhash the viewlet info. Pull out what we need.
     unhashedInfo = unhashViewletInfo(viewlethash)
     fromManagerName = unhashedInfo['managerName']
     viewletName = unhashedInfo['viewletName']
     
     reg = findTemplateViewRegistrationFromHash(viewlethash)
     
     fromViewletManager = queryMultiAdapter((self.context, self.request, self), IViewletManager, fromManagerName)
     fromManagerInterface = list(providedBy(fromViewletManager).flattened())[0]
     toViewletManager = queryMultiAdapter((self.context, self.request, self), IViewletManager, toManagerName)
     toManagerInterface = list(providedBy(toViewletManager).flattened())[0]
     
     # Create a new tuple of the "required" interfaces.
     reqList = list(reg.required)
     pos = reqList.index(fromManagerInterface)
     reqList[pos] = toManagerInterface
     reqs = tuple(reqList)
     
     registration.createTTWViewTemplate(reg)
     attr, pt = findViewletTemplate(reg.factory)
     reg.factory.template = mangleAbsoluteFilename(pt.filename)
     
     # Register the new adapter
     gsm = getGlobalSiteManager()
     gsm.registerAdapter(name=viewletName, required=reqs, provided=reg.provided, factory=reg.factory)
     
     # "Customize" it to force persistence
     reqstr = ','.join([a.__identifier__ for a in reqs])
     toreg = registration.findTemplateViewRegistration(reqstr, viewletName)
     viewzpt = registration.customizeTemplate(toreg)
     
     sm = getSiteManager(self.context)
     sm.registerAdapter(viewzpt, required=toreg.required, provided=toreg.provided, name=toreg.name)
     
     # Hide the original
     self.hideViewlet(viewlethash)
     
     # Rerender the new one
     # We can't do this with a refreshProvider call because then we lose the <tal:viewletmanager> block.
     toViewletManager.update()
     ksscore = self.getCommandSet('core')
     selector = ksscore.getCssSelector('.kssattr-viewletmanagername-' + toManagerName.replace('.', '-'))
     ksscore.replaceInnerHTML(selector, toViewletManager.render())
     
     # Inspect the new viewlet
     return self.inspectViewlet(hashViewletInfo(viewletName, toManagerName, unhashedInfo['provided']))
示例#6
0
 def customizeViewlet(self, viewlethash):
     """ Display an edit form for modifiying a viewlet's template """
     logger.debug("in customizeViewlet")
     
     # Unhash the viewlet info
     unhashedViewletInfo = unhashViewletInfo(viewlethash)
     
     # Get the viewlet's registration information from portal_view_customizations
     container = queryUtility(IViewTemplateContainer)
     reg = findTemplateViewRegistrationFromHash(viewlethash)
     regInfo = list(registration.templateViewRegistrationInfos([reg]))[0]
     
     # TODO We should be looking at regInfo['customized'] to determine whether or not a customization exists.
     # It never seems to have a value though... check on this.
     templateName = registration.generateIdFromRegistration(reg)
     
     # Check to see if the viewlet has already been customized. Get the template code accordingly.
     if templateName not in container.objectIds():
         viewzpt = registration.customizeTemplate(reg)
         sm = getSiteManager(self.context)
         sm.registerAdapter(viewzpt, required= reg.required, provided = reg.provided, name=reg.name)
     else:
         viewzpt = container[templateName]
     templateCode = viewzpt.read()
     template = ViewPageTemplateFile('panel_customize_viewlet.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(templateURL = viewzpt.absolute_url(),
                    viewletHash = viewlethash,
                    templateCode = templateCode)
     
     # Dump the output to the output panel
     self.updatePanelBodyContent(out)
     
     # Force a resize update of the panel so that the form elements are sized to the dimensions of the panel.
     kssglo = self.getCommandSet('gloWorm')
     kssglo.forceGlowormPanelResize()
     
     return self.render()
示例#7
0
 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