[Zope] Re: [Zope-dev] Need for "aq_base" in DTML(was: Re: [Zope] Dumb DTML question - existance check of an object) question - existance check of an object)

Dieter Maurer dieter@handshake.de
Thu, 27 Jul 2000 23:04:16 +0200 (CEST)


Steve Alexander writes:
 > >  * Existence check: "_.hasattr(object,what)"
 > >      NOTE, that this is the sloppy part.
 > > 
 > >       - "_.hasattr" will return true, if "object" has
 > >         attribute "what" (that is what we want)
 > >         *OR* when it has acquired such an attribute
 > >         (we do *NOT* want that here).
 > > 
 > >         What we would need is a DTML accessible version
 > >         of "aq_base". This is trivially handled by
 > >         an external method.
 > 
 > Can you do this with the following in DTML?
 > 
 >   <dtml-with "PARENTS[-1]" only>
 >     <dtml-if "_.hasattr(object, what)">
 >         ...stuff...
 >     </dtml-if>
 >   </dtml-with>
It may work for "PARENTS[-1]" but it can not be generalized:

  The DTML namespace is essentially a stack of mappings.
  The "with" tag with the "only" attribute starts a new
  stack and pushes the object onto this new stack.
  Inside the "with", you will only see attributes of
  the object itself *or* attributes that the object
  acquired. This "or" is the problem.

  Acquisition and namespace stacking are orthogonal.
  You strip the namespace stacking with the "only"
  attribute (of the "with" tag), you strip the acquisition context with
  the "aq_base" attribute (of the object).


Dieter