[Zope] siblings of me, rather than of parent

Randall Kern randy@teamkern.net
Sun, 3 Dec 2000 23:08:27 -0800


This is a multi-part message in MIME format.

------=_NextPart_000_1D4D_01C05D7D.F1EED430
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Sorry, my __bobo_traverse__ method is working, the PARENTS stack is =
exactly as I would hope, with my module as the parent of the category, =
rather than the root.

Here's the whole story:

/
    index_html    (dtml method)
    index.html    (dtml method)
    category (Folder)
        foo.html    (dtml method)
    blah    (Module)
        category (Folder)
            header.html    (dtml method)
    weather    (Category)

/index_html:
    <dtml-var index.html>

/index.html:
    <dtml-var standard_html_header>

    <dtml-if expr=3D"meta_type =3D=3D 'Category'">    <!-- true in cases =
of url like /blah/weather -->
        <dtml-call expr=3D"REQUEST.set('splevel', category)">
    </dtml-if>

    <dtml-with splevel mapping>
        <dtml-var header.html>
    </dtml-with>

    <dtml-var standard_html_footer>


Now, what I hope to happen is that the dtml-with would bind to the =
/blah/category folder, and therefore be able to find header.html.  =
However, somehow it's getting the /category folder instead, which =
doesn't have header.html.

Anyone understand why this is happening?

Thanks again,
-Randy
  ----- Original Message -----=20
  From: Randall Kern=20
  To: zope@zope.org=20
  Sent: Sunday, December 03, 2000 8:08 PM
  Subject: [Zope] siblings of me, rather than of parent


  My site has two main classes of objects, Modules (and their =
derivatives), and Categories.  A normal setup might look something like =
this:

  root
      blab    (Module)
      weather (Category)
          rain (Category)
          sun (Category)
      region (Category)

  I need to handle URLs like /root/blab/weather.  The problem is that I =
need weather.__of__(blab) on the stack, rather than weather.__of__(root) =
on top.  This is because blab (in some cases) overrides default =
behaviors from root.

  I thought the proper way to do this was by adding a __bobo_traverse__ =
method to my Module, like this:

     def __bobo_traverse__(self, REQUEST, name):
          try:
              parents =3D REQUEST['PARENTS']
              parent =3D parents[-2]
              if hasattr(parent, name):
                  ob =3D getattr(parent, name)
                  if ob.meta_type =3D=3D 'Category':
                      return ob.aq_inner.__of__(self)
          except:
              pass

          return getattr(self, name)

  =20
  But that doesn't seem to change anything, although it does perform the =
return (and doesn't throw any exceptions.)
  =20
  Basically, I'm trying to offer my siblings as if they were my =
children, so if they fail to offer something, it will be looked for in =
me, rather than my parent.
  =20
  Thanks,
  -Randy

------=_NextPart_000_1D4D_01C05D7D.F1EED430
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Sorry, my __bobo_traverse__ method is =
working, the=20
PARENTS stack is exactly as I would hope, with my module as the parent =
of the=20
category, rather than the root.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here's the whole story:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>/</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
index_html&nbsp;&nbsp;&nbsp;=20
(dtml method)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
index.html&nbsp;&nbsp;&nbsp;=20
(dtml method)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; category =
(Folder)</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo.html&nbsp;&n=
bsp;&nbsp;=20
(dtml method)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
blah&nbsp;&nbsp;&nbsp;=20
(Module)</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; category=20
(Folder)</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
header.html&nbsp;&nbsp;&nbsp; (dtml method)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
weather&nbsp;&nbsp;&nbsp;=20
(Category)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>/index_html:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &lt;dtml-var=20
index.html&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>/index.html:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &lt;dtml-var=20
standard_html_header&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &lt;dtml-if =
expr=3D"meta_type =3D=3D=20
'Category'"&gt;&nbsp;&nbsp;&nbsp; &lt;!-- true in cases of url like=20
/blah/weather --&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&lt;dtml-call=20
expr=3D"REQUEST.set('splevel', category)"&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
&lt;/dtml-if&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &lt;dtml-with =
splevel=20
mapping&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&lt;dtml-var=20
header.html&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
&lt;/dtml-with&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &lt;dtml-var=20
standard_html_footer&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Now, what I hope to happen is that the =
dtml-with=20
would bind to the /blah/category folder, and therefore be able to find=20
header.html.&nbsp; However, somehow it's getting the /category folder =
instead,=20
which doesn't have header.html.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Anyone understand why this is=20
happening?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks again,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>-Randy</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A href=3D"mailto:randy@teamkern.net" =
title=3Drandy@teamkern.net>Randall Kern</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:zope@zope.org"=20
  title=3Dzope@zope.org>zope@zope.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Sunday, December 03, 2000 =
8:08=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Zope] siblings of me, =
rather=20
  than of parent</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>My site has two main classes of =
objects, Modules=20
  (and their derivatives), and Categories.&nbsp; A normal setup might =
look=20
  something like this:</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>root</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; =
blab&nbsp;&nbsp;&nbsp;=20
  (Module)</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; weather=20
(Category)</FONT></DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rain=20
  (Category)</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
sun=20
  (Category)</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; region =
(Category)</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>I need to handle URLs like=20
  /root/blab/weather.&nbsp; The problem is that I need =
weather.__of__(blab) on=20
  the stack, rather than weather.__of__(root) on top.&nbsp; This is =
because blab=20
  (in some cases) overrides default behaviors from root.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>I thought the proper way to do this =
was by adding=20
  a __bobo_traverse__ method to my Module, like this:</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; def =
__bobo_traverse__(self, REQUEST,=20
  name):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
try:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
  parents =3D=20
  =
REQUEST['PARENTS']<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;=20
  parent =3D=20
  =
parents[-2]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
  if hasattr(parent,=20
  =
name):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  ob =3D getattr(parent,=20
  =
name)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;=20
  if ob.meta_type =3D=3D=20
  =
'Category':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  return =
ob.aq_inner.__of__(self)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
except:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
  pass</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
  getattr(self, name)<BR></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>But that doesn't seem to change =
anything,=20
  although it does perform the return (and doesn't throw any=20
  exceptions.)</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Basically, I'm trying to offer my =
siblings as if=20
  they were my children, so if they fail to offer something, it will be =
looked=20
  for in me, rather than my parent.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
  <DIV><FONT face=3DArial =
size=3D2>-Randy</DIV></BLOCKQUOTE></FONT></BODY></HTML>

------=_NextPart_000_1D4D_01C05D7D.F1EED430--