[Zope] Testing multiple values for existance - still

Oliver Sturm sturm@oliver-sturm.de
Mon, 24 Sep 2001 12:40:17 +0200


Hi!

I recently had the following question:

> I can do <dtml-if foo> to test if foo is known at all. Why can't I do
> <dtml-if "foo or bar"> to test if either foo or bar are known? I get a
> "Name Error" saying something like "global name 'foo' is not defined" if I
> do this (and foo is actually undefined). Is there a different syntax for
> this?

which was answered quickly by marc lindahl <marc@bowery.com> with 

> Try testing for existence first -- hasattr()

and by Steve Drees <drees@rangebroadband.com> with 

> <dtml-if "REQUEST.has_key('foo') or REQUEST.has_key('bar')">

Thanks to you two. I didn't have time to look into the issue further, but I
have now, and I'm sorry to say it still doesn't work. This is probably due
to my ignorance, but I fail to understand how this works. The version

<dtml-if "REQUEST.has_key('foo') or REQUEST.has_key('bar')">

doesn't work for me because neither foo nor bar are in the REQUEST, they are
simply dtml methods that may be in the current folder, or they may be not.
How do I test for that? Why does the method I'm using for one object (see
above) not work for more than one object? Is that simply syntactically
inconsistent or am I missing something?

Now, as to hasattr(), I simply don't see what to do with that. I tried
<dtml-if "_.hasattr('foo') or _.hasattr('bar')"> after a while which tells
me I need to use three arguments, but not what those are. I also tried
<dtml-if "objectValues().hasattr('foo')"> which I simply find logical, but
it also does not work. This is certainly all stupid. I tried searching
zope.org for all keywords involved and found thousands of pages that use
these keywords themselves (is that really what fulltext search is about?).

Where in the world (or on the web, rather) is there some clear documentation
that has information on those topics? I have been using Zope for more than a
year now (in case you were already wondering :-), I have 15 years of
programming experience, and I'm stunned all the time by how difficult and
unintuitive everything Zope seems to be as soon as I look under the hood.
I'm sure that's not really the case, but hints to some proof would be very
much appreciated. Thanks!

Oliver

-- 
Oliver Sturm / <sturm@oliver-sturm.de>