[Zope3-dev] Using parent references rather than context wrappers to represent containment

Martijn Faassen faassen at vet.uu.nl
Mon Aug 11 19:16:55 EDT 2003


Jim Fulton wrote:
> One problem is that we use the context information to compute
> absolute URLs and sometimes we do this for views.  A view instances
> otherwise has no way of knowing what name it was accessed with.
> 
> >Perhaps it would be useful to add another interface to make something
> >context aware. IContained can be adapted to IContextAware. Views also 
> >implement IContextAware (but not IContained), and their behavior could 
> >then be to look for their 'context' attribute as their context.
> 
> Right. Unfortunately, we need more than context. We also need the
> name. IContextAware could include the name.

Ah, now I see why it is tempting to use IContained here. But it might
still be useful to separate this out and have a very minimal 
IContextAware which has a name and a way to get to the context.

[I forget which context I wrote this in :)]
> >If something is not context aware at all, lookups simply fail.
> 
> I find this unacceptable for component lookup,
> as context awareness should not be a prerequisite for using
> the component architecture.

Yes, I think there's a tension between this requirement and debuggability
here. Context awareness can be added to existing objects using a decorator
or adapter though, right?

Container awareness I agree should not be a requirement
for the component architecture, but a form of context awareness (that
can be added using a decorator if the object itself does not support it)
seems to be essential conceptually, as this determines where the lookups take
place.

One could explain this by saying that *any* python object can be
adapted to IContextAware. If a python object does not specify context 
awareness itself, Zope adapts this to a IContextAware implementation
that returns the global context. 

If I instead want a warning or error when my object is not in any context, 
I could configure matters in such a way that my objects are adapted to an
*empty* context if nothing can be found based on a container check, not
the global context. This way I could get my error.

Regards,

Martijn




More information about the Zope3-dev mailing list