Example #1
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']))
Example #2
0
 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)