def __call__(self, econtext):
        name = StringExpr.__call__(self, econtext)
        context = econtext.vars['context']
        request = econtext.vars['request']
        view = econtext.vars['view']

        # Try to look up the provider.
        provider = zope.component.queryMultiAdapter(
            (context, request, view), interfaces.IContentProvider, name)

        # Provide a useful error message, if the provider was not found.
        if provider is None:
            raise interfaces.ContentProviderLookupError(name)

        if getattr(provider, '__of__', None) is not None:
            provider = provider.__of__(context)

        # Insert the data gotten from the context
        addTALNamespaceData(provider, econtext)

        # Stage 1: Do the state update.
        provider.update()

        # Stage 2: Render the HTML content.
        return provider.render()
Exemple #2
0
    def __call__(self, econtext):
        name = super(ProviderExpression, self).__call__(econtext)
        view = econtext.vars['view']
        context = view.context
        request = view.request

        # Try to look up the provider.
        provider = zope.component.queryMultiAdapter(
            (context, request, view), interfaces.IContentProvider, name)

        # Provide a useful error message, if the provider was not found.
        if provider is None:
            raise interfaces.ContentProviderLookupError(name)

        # add the __name__ attribute if it implements ILocation
        if ILocation.providedBy(provider):
            provider.__name__ = name

        # Insert the data gotten from the context
        addTALNamespaceData(provider, econtext)

        # Stage 1: Do the state update.
        zope.event.notify(interfaces.BeforeUpdateEvent(provider, request))
        provider.update()

        # Stage 2: Render the HTML content.
        return provider.render()
    def __call__(self, econtext):
        name = super(Z2ProviderExpression, self).__call__(econtext)
        context = econtext.vars['context']
        request = econtext.vars['request']
        view = econtext.vars['view']

        # Try to look up the provider.
        provider = zope.component.queryMultiAdapter(
            (context, request, view), cp_interfaces.IContentProvider, name)

        # Provide a useful error message, if the provider was not found.
        if provider is None:
            raise cp_interfaces.ContentProviderLookupError(name)

        # XXX We can either wrap this in the context and have three test
        # failures in directives.txt or wrap it in the view (aka our
        # __parent__) and have one test failure in provider.txt which also
        # happens when we don't wrap this at all anymore :(
        # Removing all the AQ-wrapping is probably the way to go here.
        if getattr(provider, '__of__', None) is not None:
            provider = provider.__of__(context)

        # Insert the data gotten from the context
        addTALNamespaceData(provider, econtext)

        # Stage 1: Do the state update.
        provider.update()

        # Stage 2: Render the HTML content.
        return provider.render()
Exemple #4
0
    def render(self, scriptingContext, name, **kwargs):
        """
        The code is took from Products.five.browser.providerexpression.

        @param scriptingContext: Instance of collective.templateengines.interfaces.ITemplateContext        
        """

        # Get traversing context
        mappings = scriptingContext.getMappings()
        context = mappings["context"]
        request = mappings["request"]

        class Dummy(BrowserView):
            pass

        context = context
        request = request
        view = Dummy(context, request)
        view = view.__of__(context)

        # Try to look up the provider.
        provider = zope.component.queryMultiAdapter(
            (context, request, view), cp_interfaces.IContentProvider, name)

        # Provide a useful error message, if the provider was not found.
        if provider is None:
            raise cp_interfaces.ContentProviderLookupError(
                "Cannot find content provider:" + name)

        if getattr(provider, '__of__', None) is not None:
            provider = provider.__of__(context)

        # Stage 1: Do the state update.
        provider.update()

        # Stage 2: Render the HTML content.
        return provider.render()