Exemplo n.º 1
0
    def page_content(self):
        """Get traversable content providers for the context.

        Say, we have a viewlet manager named ExtraInfo, registered for persons.
        As viewlet managers implement IContentProvider, we can do:

        <div tal:repeat="person view/persons">
          <p tal:content="person/title"></p>
          <div tal:replace="structure person/schooltool:page_content/ExtraInfo"></div>
        </div>

        """
        if self.engine is None:
            return None
        vars = self.engine.vars
        context = self.context
        request = vars.get('request', None)
        page = view = vars.get('view', None)
        while (page is not None and
               not IPageBase.providedBy(page)):
            page = getattr(page, '__parent__', None)
        if page is None:
            page = view
            while (page is not None and
                   not IBrowserPage.providedBy(page)):
                page = getattr(page, '__parent__', None)
        providers = queryMultiAdapter(
            (context, request, page),
            IContentProviders)
        if ITALESFunctionNamespace.providedBy(providers):
            providers.setEngine(self.engine)
        return providers
Exemplo n.º 2
0
    def _eval(self, econtext,
              isinstance=isinstance):
        vars = econtext.vars

        compiled_path = self._compiled_path

        base = self._base
        if base == 'CONTEXTS' or not base:  # Special base name
            ob = econtext.contexts
        else:
            ob = vars[base]
        if isinstance(ob, DeferWrapper):
            ob = ob()

        for element in compiled_path:
            if isinstance(element, tuple):
                ob = self._traverser(ob, element, econtext)
            elif isinstance(element, basestring):
                val = vars[element]
                # If the value isn't a string, assume it's a sequence
                # of path names.
                if isinstance(val, basestring):
                    val = (val,)
                ob = self._traverser(ob, val, econtext)
            elif callable(element):
                ob = element(ob)
                # TODO: Once we have n-ary adapters, use them.
                if ITALESFunctionNamespace.providedBy(ob):
                    ob.setEngine(econtext)
            else:
                raise "Waagh!"
        return ob
Exemplo n.º 3
0
    def _eval(self, econtext, isinstance=isinstance):
        vars = econtext.vars

        compiled_path = self._compiled_path

        base = self._base
        if base == 'CONTEXTS' or not base:  # Special base name
            ob = econtext.contexts
        else:
            ob = vars[base]
        if isinstance(ob, DeferWrapper):
            ob = ob()

        for element in compiled_path:
            if isinstance(element, tuple):
                ob = self._traverser(ob, element, econtext)
            elif isinstance(element, six.string_types):
                val = vars[element]
                # If the value isn't a string, assume it's a sequence
                # of path names.
                if isinstance(val, six.string_types):
                    val = (val, )
                ob = self._traverser(ob, val, econtext)
            elif callable(element):
                ob = element(ob)
                # TODO: Once we have n-ary adapters, use them.
                if ITALESFunctionNamespace.providedBy(ob):
                    ob.setEngine(econtext)
            else:
                raise ValueError(repr(element))
        return ob