Example #1
0
    def exit(self, request):
        if self._commit:
            # Introspect the commit function to see what 
            #arguments it takes
            func = self._commit
            if hasattr(func, 'im_func'):
                func = func.im_func
            args, varargs, varkw, defaults = inspect.getargspec(func)
            self.numArgs = len(args)
            wantsRequest = args[1] == 'request'
            if wantsRequest:
                numArgs -= 1
        else:
            # Introspect the template to see if we still have
            # controllers that will be giving us input
            
            # aggregateValid is called before the view renders the node, so
            # we can count the number of controllers below us the first time
            # we are called
            if not hasattr(self, 'numArgs'):
                self.numArgs = len(domhelpers.findElementsWithAttributeShallow(
                    self.view.node, "controller"))

        if self._invalidList:
            self._parent.aggregateInvalid(request, self, self._invalidList)
        else:
            if self._commit:
                if wantsRequest:
                    self._commit(request, *self._validList)
                else:
                    self._commit(*self._validList)
            self._parent.aggregateValid(request, self, self._invalidList)
Example #2
0
 def generate(self, request, node):
     if self.macroTemplate:
         templ = view.View(
             self.model,
             template = self.macroTemplate).lookupTemplate(request)
     else:
         templ = view.View(
             self.model,
             templateFile=self.macroFile,
             templateDirectory=self.macroFileDirectory).lookupTemplate(request)
     macrolist = domhelpers.locateNodes(templ.childNodes, "macro", self.macroName)
     assert len(macrolist) == 1, ("No macro or more than "
         "one macro named %s found." % self.macroName)
     macro = macrolist[0]
     del macro.attributes['macro']
     slots = domhelpers.findElementsWithAttributeShallow(macro, "slot")
     for slot in slots:
         slotName = slot.attributes.get("slot")
         fillerlist = domhelpers.locateNodes(node.childNodes, "fill-slot", slotName)
         assert len(fillerlist) <= 1, "More than one fill-slot found with name %s" % slotName
         if len(fillerlist):
             filler = fillerlist[0]
             filler.tagName = filler.endTagName = slot.tagName
             del filler.attributes['fill-slot']
             del slot.attributes['slot']
             filler.attributes.update(slot.attributes)
             slot.parentNode.replaceChild(filler, slot)
     return macro
Example #3
0
    def generate(self, request, node):
        templ = view.View(
            self.model,
            templateFile=self.macroFile, 
            templateDirectory=self.macroFileDirectory).lookupTemplate(request)

        ## We are going to return the macro node from the metatemplate,
        ## after replacing any slot= nodes in it with fill-slot= nodes from `node'
        macrolist = domhelpers.locateNodes(templ.childNodes, "macro", self.macroName)
        assert len(macrolist) == 1, ("No macro or more than "
            "one macro named %s found." % self.macroName)

        macro = macrolist[0]
        macro.removeAttribute('macro')
        slots = domhelpers.findElementsWithAttributeShallow(macro, "slot")
        for slot in slots:
            slotName = slot.getAttribute("slot")
            fillerlist = domhelpers.locateNodes(node.childNodes, "fill-slot", slotName)
            assert len(fillerlist) <= 1, "More than one fill-slot found with name %s" % slotName
            if len(fillerlist):
                filler = fillerlist[0]
                filler.tagName = filler.endTagName = slot.tagName
                filler.removeAttribute('fill-slot')
                slot.removeAttribute('slot')
                for k, v in slot.attributes.items():
                    filler.setAttribute(k, v)
                slot.parentNode.replaceChild(filler, slot)

        return macro
Example #4
0
 def exit(self, request):
     if self._commit:
         func = self._commit
         if hasattr(func, 'im_func'):
             func = func.im_func
         args, varargs, varkw, defaults = inspect.getargspec(func)
         self.numArgs = len(args)
         wantsRequest = args[1] == 'request'
         if wantsRequest:
             numArgs -= 1
     else:
         if not hasattr(self, 'numArgs'):
             self.numArgs = len(domhelpers.findElementsWithAttributeShallow(
                 self.view.node, "controller"))
     if self._invalidList:
         self._parent.aggregateInvalid(request, self, self._invalidList)
     else:
         if self._commit:
             if wantsRequest:
                 self._commit(request, *self._validList)
             else:
                 self._commit(*self._validList)
         self._parent.aggregateValid(request, self, self._invalidList)