Example #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()
Example #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()
Example #3
0
    def __iter__(self):
        """ Returns an iterator enumerating the resources of this type. """
        pvc = getToolByName(getSite(), 'portal_view_customizations')
        layer_precedence = self.layer_precedence()
        by_layer_precedence_and_ttwness = lambda x: (layer_precedence.index(x.required[1]), int(not ITTWViewTemplate.providedBy(x.factory)))
        regs = sorted(self.iter_view_registrations(), key=by_layer_precedence_and_ttwness)

        for info in templateViewRegistrationInfos(regs, mangle=False):
            required = info['required'].split(',')
            res = ViewResourceRegistration()
            res.name = info['viewname']
            res.context = context = required[0]
            if context == 'zope.interface.Interface':
                context = '*'
            res.description = translate(_('View for X',
                                default = u'View for ${context}',
                                mapping = {u'context': context}))
            res.layer = required[1]
            res.actions = []
            res.tags = ['template']
            res.path = None
            if info['customized']:
                res.tags.append('customized')
                obj = getattr(pvc, info['customized'])
                res.path = '/'.join(obj.getPhysicalPath())
                res.text = obj._text
                res.info = translate(_('In the database',
                             default = u'In the database: ${path}',
                             mapping = {'path': res.path}))
                res.actions.append(('Edit', obj.absolute_url() + '/manage_main'))
                remove_url = pvc.absolute_url() + '/manage_delObjects?ids=' + info['customized']
                res.actions.append(('Remove', remove_url))
            else:
                res.path = info['zptfile']
                res.info = translate(_(u"On the filesystem", 
                               default=u"On the filesystem: ${path}",
                               mapping={u"path" : res.path}))
                view_url = pvc.absolute_url() + '/@@customizezpt.html?required=%s&view_name=%s' % (info['required'], info['viewname'])
                res.actions.append(('View', view_url))
            name = info['viewname'].lower()
            if name.endswith('.css'):
                res.tags.append('stylesheet')
            elif name.endswith('.js'):
                res.tags.append('javascript')
            elif name.endswith('.kss'):
                res.tags.append('kss')
            elif name.endswith('.jpg') or name.endswith('.gif') or name.endswith('.png'):
                res.tags.append('image')
                
            yield res
Example #4
0
 def __iter__(self):
     """ Returns an iterator enumerating the resources of this type. """
     pvc = getToolByName(getSite(), 'portal_view_customizations')
     layer_precedence = self.layer_precedence()
     by_layer_precedence_and_ttwness = lambda x: (layer_precedence.index(x.required[1]), int(not ITTWViewTemplate.providedBy(x.factory)))
     regs = sorted(self.iter_portlet_registrations(), key=by_layer_precedence_and_ttwness)
    
     for info in templateViewRegistrationInfos(regs, mangle=False):
         required = info['required'].split(',')
         res = PortletResourceRegistration()
         res.name = info['viewname']
         res.context = required[0], required[3]
         context = required[0]
         if context == 'zope.interface.Interface':
             context = '*'
         res.description = translate(_('portlet for X in the manager Y',
                             default = u'Portlet for ${context} in the ${manager} manager',
                             mapping = {'context': context, 'manager':
                                                        required[3]}))
         res.layer = required[1]
         res.actions = []
         res.tags = ['portlet']
         res.path = None
         if info['customized']:
             res.tags.append('customized')
             obj = getattr(pvc, info['customized'])
             path = '/'.join(obj.getPhysicalPath())
             res.text = obj._text
             res.info = translate(_(u"In the database", 
                            default=u"In the database: ${path}",
                            mapping={u"path" : path}))
             res.actions.append((PMF(u'Edit'), obj.absolute_url() + '/manage_main'))
             remove_url = pvc.absolute_url() + '/manage_delObjects?ids=' + info['customized']
             res.actions.append((PMF(u'Remove'), remove_url))
         else:
             res.path = info['zptfile']
             res.info = translate(_(u"On the filesystem", 
                            default=u"On the filesystem: ${path}",
                            mapping={u"path" : res.path}))
             view_url = pvc.absolute_url() + '/@@customizezpt.html?required=%s&view_name=%s' % (info['required'], info['viewname'])
             res.actions.append((PMF(u'View'), view_url))
         yield res
Example #5
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()
Example #6
0
 def getTemplateViewRegistrationInfo(self):
     reg = self.getRegistrationFromRequest()
     return list(registration.templateViewRegistrationInfos([reg]))[0]
Example #7
0
 def getTemplateViewRegistrationInfo(self):
     reg = self.getRegistrationFromRequest()
     return list(registration.templateViewRegistrationInfos([reg]))[0]