Exemplo n.º 1
0
    def setDataCallback(self, result, request, node):
        model = result
        view = None
        if isinstance(model, components.Componentized):
            view = model.getAdapter(interfaces.IView)
        if not view and hasattr(model, '__class__'):
            view = interfaces.IView(model, None)

        if view:
            view["id"] = self.attributes.get('id', '')
            view.templateNode = node
            view.controller = self.controller
            return view.setDataCallback(result, request, node)
        else:
            return Widget.setDataCallback(self, result, request, node)
Exemplo n.º 2
0
 def setDataCallback(self, result, request, node):
     model = result
     view = None
     if isinstance(model, components.Componentized):
         view = model.getAdapter(interfaces.IView)
     if not view and hasattr(model, '__class__'):
         view = interfaces.IView(model, None)
     
     if view:
         view["id"] = self.attributes.get('id', '')
         view.templateNode = node
         view.controller = self.controller
         return view.setDataCallback(result, request, node)
     else:
         return Widget.setDataCallback(self, result, request, node)
Exemplo n.º 3
0
    def getNodeView(self, request, node, submodel, model):
        view = None
        viewName = node.attributes.get('view')

        if model is None:
            model = peek(self.modelStack)

        # Look up a view factory.
        if viewName:
            viewStack = self.viewStack
            while viewStack is not None:
                namespace, viewStack = viewStack
                if namespace is None:
                    continue
                try:
                    view = namespace.getSubview(request, node, model, viewName)
                except AttributeError:
                    # Was that from something in the viewStack that didn't
                    # have a getSubview?
                    if not hasattr(namespace, "getSubview"):
                        log.msg("Warning: There is no getSubview on %r" %
                                (namespace,))
                        continue
                    else:
                        # No, something else is really broken.
                        raise
                if view is not None:
                    break
            else:
                raise NotImplementedError(
                    "You specified view name %s on a node %s, but no "
                    "wvfactory_%s method was found in %s.  (Or maybe they were "
                    "found but they returned None.)" % (
                    viewName, node, viewName,
                    filterStack(self.viewStack)))
        elif node.attributes.get("model"):
            # If no "view" attribute was specified on the node, see if there
            # is a IView adapter registerred for the model.
            # First, see if the model is Componentized.
            if isinstance(model, components.Componentized):
                view = model.getAdapter(interfaces.IView)
            if not view and hasattr(model, '__class__'):
                view = components.getAdapter(model,
                                interfaces.IView,
                                None,
                                components.getAdapterClassWithInheritance)

        return view
Exemplo n.º 4
0
    def getNodeView(self, request, node, submodel, model):
        view = None
        viewName = node.attributes.get('view')

        if model is None:
            model = peek(self.modelStack)

        # Look up a view factory.
        if viewName:
            viewStack = self.viewStack
            while viewStack is not None:
                namespace, viewStack = viewStack
                if namespace is None:
                    continue
                try:
                    view = namespace.getSubview(request, node, model, viewName)
                except AttributeError:
                    # Was that from something in the viewStack that didn't
                    # have a getSubview?
                    if not hasattr(namespace, "getSubview"):
                        log.msg("Warning: There is no getSubview on %r" %
                                (namespace, ))
                        continue
                    else:
                        # No, something else is really broken.
                        raise
                if view is not None:
                    break
            else:
                raise NotImplementedError(
                    "You specified view name %s on a node %s, but no "
                    "wvfactory_%s method was found in %s.  (Or maybe they were "
                    "found but they returned None.)" %
                    (viewName, node, viewName, filterStack(self.viewStack)))
        elif node.attributes.get("model"):
            # If no "view" attribute was specified on the node, see if there
            # is a IView adapter registerred for the model.
            # First, see if the model is Componentized.
            if isinstance(model, components.Componentized):
                view = model.getAdapter(interfaces.IView)
            if not view and hasattr(model, '__class__'):
                view = components.getAdapter(
                    model, interfaces.IView, None,
                    components.getAdapterClassWithInheritance)

        return view
Exemplo n.º 5
0
 def getNodeView(self, request, node, submodel, model):
     view = None
     viewName = node.attributes.get('view')
     if model is None:
         model = peek(self.modelStack)
     if viewName:
         viewStack = self.viewStack
         while viewStack is not None:
             namespace, viewStack = viewStack
             if namespace is None:
                 continue
             try:
                 view = namespace.getSubview(request, node, model, viewName)
             except AttributeError:
                 if not hasattr(namespace, "getSubview"):
                     log.msg("Warning: There is no getSubview on %r" %
                             (namespace,))
                     continue
                 else:
                     raise
             if view is not None:
                 break
         else:
             raise NotImplementedError(
                 "You specified view name %s on a node %s, but no "
                 "wvfactory_%s method was found in %s.  (Or maybe they were "
                 "found but they returned None.)" % (
                 viewName, node, viewName,
                 filterStack(self.viewStack)))
     elif node.attributes.get("model"):
         if isinstance(model, components.Componentized):
             view = model.getAdapter(interfaces.IView)
         if not view and hasattr(model, '__class__'):
             view = components.getAdapter(model,
                             interfaces.IView,
                             None,
                             components.getAdapterClassWithInheritance)
     return view