Exemplo n.º 1
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)
Exemplo n.º 2
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()
Exemplo n.º 3
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)
Exemplo n.º 4
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()
Exemplo n.º 5
0
def dumpPortalViewCustomization(context):
    result = []

    components = getSiteManager(context)
    localregs = [reg for reg in components.registeredAdapters() if (len(reg.required) in (2, 4, 5) and
                                                                     reg.required[1].isOrExtends(IBrowserRequest) and
                                                                     ITTWViewTemplate.providedBy(reg.factory))]
    container = getUtility(IViewTemplateContainer)
    for lreg in localregs:
        ttw_id = generateIdFromRegistration(lreg)
        if ttw_id not in container.objectIds():
            continue
        ttw = getattr(container, ttw_id)
        ttw_info = {'for_name'  : interfaceName(lreg.required[0]),
                    'type_name' : interfaceName(lreg.required[-1]),
                    'view_name' : lreg.name,
                    'kwargs'    : {'text' : ttw._text,
                                   'content_type' : ttw.content_type,
                                   'encoding' : ttw.output_encoding,
                                   }}
        result.append(ttw_info)

    return result