def templateViewRegistrationInfos(regs, mangle=True):
    for reg in regs:
        if ITTWViewTemplate.providedBy(reg.factory):
            zptfile = None
            zcmlfile = None
            name = reg.name or reg.factory.name
            customized = reg.factory.getId(
            )  # TODO: can we get an absolute url?
        else:
            attr, pt = findViewletTemplate(reg.factory)
            if attr is None:  # skip, if the factory has no template...
                continue
            zptfile = pt.filename
            zcmlfile = getattr(reg.info, 'file', None)

            if mangle:
                zptfile = mangleAbsoluteFilename(zptfile)
                zcmlfile = zcmlfile and mangleAbsoluteFilename(zcmlfile)

            name = reg.name or basename(zptfile)
            customized = None
        required = [interfaceName(r) for r in reg.required]
        required_str = ','.join(required)
        customize_url = '@@customizezpt.html?required=%s&view_name=%s' % (
            required_str, name)
        yield {
            'viewname': name,
            'required': required_str,
            'for': required[0],
            'type': required[1],
            'zptfile': zptfile,
            'zcmlfile': zcmlfile or 'n.a.',
            'customized': customized,
            'customize_url': customize_url,
        }
Example #2
0
def templateViewRegistrationInfos(regs, mangle=True):
    for reg in regs:
        if ITTWViewTemplate.providedBy(reg.factory):
            zptfile = None
            zcmlfile = None
            name = reg.name or reg.factory.name
            customized = reg.factory.getId()    # TODO: can we get an absolute url?
        else:
            attr, pt = findViewletTemplate(reg.factory)
            if attr is None:        # skip, if the factory has no template...
                continue
            zptfile = pt.filename
            zcmlfile = getattr(reg.info, 'file', None)

            if mangle:
                zptfile = mangleAbsoluteFilename(zptfile)
                zcmlfile = zcmlfile and mangleAbsoluteFilename(zcmlfile)

            name = reg.name or basename(zptfile)
            customized = None
        required = [interfaceName(r) for r in reg.required]
        required_str = ','.join(required)
        customize_url = '@@customizezpt.html?required=%s&view_name=%s' % (
                required_str,
                name)
        yield {
            'viewname': name,
            'required': required_str,
            'for': required[0],
            'type': required[1],
            'zptfile': zptfile,
            'zcmlfile': zcmlfile or 'n.a.',
            'customized': customized,
            'customize_url': customize_url,
        }
Example #3
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']))