[Zope] Simple (?) getattr question: ignore acquisition

Andy Gimblett andy.gimblett@ftech.net
Tue, 21 Aug 2001 17:52:21 +0100


Howdy...

In a nutshell: I want to get some attribute of an object without
it using acquisition - ie the attribute is returned if and only
if the object has it _itself_. I'm trying to use _.getattr() but
this is acquiring - I need something which doesn't acquire.

In more detail:

Folder "gimbo" contains two folders, "notes" and "queries".
Queries has subdirectories, some of which have a "notes" property
(a string).

In "queries", I want to use something like:

<dtml-in expr="objectValues('Folder')">
  <dtml-let f = sequence-item>
    <dtml-try>
      <dtml-var expr="_.getattr(f, 'notes')">
    <dtml-except>
      &nbsp;
    </dtml-try>
  </dtml-try>
</dtml-in>

to display the notes if they're present, and display a blank space if
they're not.

Unfortunately, for those folders which _don't_ have a notes property,
the _.getattr() call in the above is picking up the "notes" folder
from higher in the hierarchy - not what I want.

I realise that by carefully choosing names I can avoid this, but
I'd rather avoid that burden if possible.

So, is there a way of doing this which doesn't attempt to acquire?

Cheers,

-Andy

-- 
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.