[Zope] Stumped: Python in operator seems to not work

Andy Dustman adustman@comstar.net
Mon, 4 Sep 2000 20:19:40 -0400 (EDT)


(Please CC: me on responses.)

I have a DTML Method (build_navigation_bar) that is called from
standard_html_header to (surprise) build a navigation
bar. standard_html_header invokes it thusly:

<dtml-var "build_navigation_sidebar(start=_['foo'], parents=PARENTS)">

where foo is the top of the tree; standard_html_header can be acquired
further down in the tree. parents is initialized to PARENTS, which is the
list of parents of the original object. build_navigation_bar invokes
itself on Folders that it finds that are among the parents of the original
object. I.e., this is somewhat like a tree, but we only want to expand the
branch we're in. This is done with:

<dtml-in "start.objectValues(['Folder'])" sort=public skip_unauthorized>
<dtml-with sequence-item>
<dtml-if "hasProperty('public') and public">
  <A HREF="<dtml-var absolute_url>"><dtml-var title_or_id></A><BR>
  <!-- this() in parents == <dtml-var "this() in parents"> ==
       <dtml-var this> in <dtml-var parents> -->
  <dtml-if "this() in parents">
    <!-- recursing -->
    <dtml-var "build_navigation_sidebar(start=this(), parents=parents)">
  </dtml-if>
</dtml-if>
</dtml-with>
</dtml-in>

Unfortunately, this doesn't work: The conditional is always false. Some of
the debugging output:

<!-- this() in parents == 0 == <Folder instance at 89d9850> in
[<Folder instance at 87b2cc8>, <Folder instance at 8a22420>, <Application
instance at 87b9158>] -->
<!-- this() in parents == 0 == <Folder instance at 87b2cc8> in
[<Folder instance at 87b2cc8>, <Folder instance at 8a22420>, <Application
instance at 87b9158>] -->

Note that in the first line, the expression correctly evaluates to 0,
while the second line incorrectly evaluates to 0. Using <dtml-var
"this()"> should not, and does not, make a difference. Initializing
parents with a copy of PARENTS (PARENTS[:]) does not make a difference, as
expected. Direct comparisons, i.e. <dtml-var "this() is parents[0]"> (or
==) also fail.

What did I overlook, because this seems like it ought to work.

-- 
andy dustman       |     programmer/analyst     |      comstar.net, inc.
telephone: 770.485.6025 / 706.549.7689 | icq: 32922760 | pgp: 0xc72f3f1d
"Therefore, sweet knights, if you may doubt your strength or courage, 
come no further, for death awaits you all, with nasty, big, pointy teeth!"