[Zope-dev] Re: [Zope 2.11] Stepping forward and going beta

Hanno Schlichting plone at hannosch.info
Sun Dec 9 08:21:45 EST 2007


Sidnei da Silva wrote:
> On Dec 9, 2007 5:30 AM, Andreas Jung <lists at zopyx.com> wrote:
>> Objections? Thoughts?
> 
> That branch didn't look like it was far off being finished. Is there a
> TODO of what is pending to finish it?

The good news is that all Zope tests are passing and all the heavy
lifting is done. The bad news is that there is one rather nasty minor
problem with the branch.

Now we were able to remove Acquistion wrapping and base classes from a
lot of places in Five. In almost all places this would cause no problem,
and following __parent__ pointers instead would do the trick. The only
place where this turned out to be tricky is the ViewPageTemplateFile aka
ZopeTwoPageTemplateFile of Five (found in
Products.Five.browser.pagetemplatefile).

The main difference between the Zope3 and the former Zope2 version is
the way those get to know the view which they operate on. In Zope3 the
view is always passed in as the first argument to the __call__ method,
the argument is called instance here.

The Zope2 version so far depended on Acquisition to get to the view. As
we removed Acquisition wrapping from a lot of places, the
ViewPageTemplateFile doesn't have any proper AQ context anymore to work
with. For most cases this isn't a problem as the view is passed in as
the first argument as well in Zope2, but looking through the Plone
codebase (which we used as a real-life testcase for interesting uses of
Five technology) it turned out that there are various different ways of
usage out there, which wouldn't pass in the view. Those do work right
with current Zope and obviously need to keep working for BBB reasons.

The only way I found to get this working without reintroducing
AQ-wrapping all over the place again, which kind of defeats the purpose
of this branch, is to walk up the stack frames to get to the view. I
hacked this version just yesterday and it still produces some
TraversalError for 'macros' in some cases. If you want to test this,
just create a Plone instance from the Plone 3 SVN branch, try
inline-editing on the front-page, @@manage-portlets, creating a new
content-rule inside the control panel and looking at the mail control
panel. These all use ViewPageTemplateFiles in various different ways and
so far I haven't been able to get all of them working at the same time.

Hanno

P.S. If you want to see my latest attempt at writing horrible code, this
is the new __call__ method for Five's ViewPageTemplateFile:

def __call__(self, *args, **keywords):
    instance = None
    # Ensure that the first argument is the instance
    if len(args) > 0:
        instance, args = args[0], args[1:]
        if not IBrowserView.providedBy(instance):
            # The first arg is not the desired instance. Put the first
            # argument back into the list.
            args = list(args)
            args.insert(0, instance)
            instance = None

    # XXX! This isn't a particular nice way to get the instance.
    def _acquireInstance():
        instance = None
        for i in range(2, 7):
            instance = sys._getframe(i).f_locals['self']
            if IBrowserView.providedBy(instance):
                break
        return instance

    if instance is None:
        instance = _acquireInstance()

    # Copied the code from zope.app.pagetemplate as we need to pass on
    # the keywords which might contain one named 'instance', which would
    # conflict with the first required arg of that method. KSS does this
    # as an example and needs instance to be present in the options.
    # TODO: Maybe we should emit a warning for the instance keyword.
    namespace = self.pt_getContext(
        request=instance.request,
        instance=instance, args=args, options=keywords)
    debug_flags = instance.request.debug
    s = self.pt_render(
        namespace,
        showtal=getattr(debug_flags, 'showTAL', 0),
        sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
        )
    response = instance.request.response
    if not response.getHeader("Content-Type"):
        response.setHeader("Content-Type", self.content_type)
    return s



More information about the Zope-Dev mailing list