[Zope] siblings of me, rather than of parent
Randall Kern
randy@teamkern.net
Mon, 4 Dec 2000 10:03:56 -0800
This is a multi-part message in MIME format.
------=_NextPart_000_1E90_01C05DD9.83B5F3C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
ahahhaha!!! (sorry, been up _way_ too long.)
the trick was returning ob.aq_base.__of__(self), not =
ob.aq_inner.__of__(self)!
Seems to work great now.
-Randy
----- Original Message -----=20
From: Randall Kern=20
To: zope@zope.org=20
Sent: Sunday, December 03, 2000 11:08 PM
Subject: Re: [Zope] siblings of me, rather than of parent
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_1E90_01C05DD9.83B5F3C0
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>ahahhaha!!! (sorry, been up _way_ =
too=20
long.)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>the trick was returning =
ob.aq_base.__of__(self),=20
not ob.aq_inner.__of__(self)!</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Seems to work great now.</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 =
11:08=20
PM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [Zope] siblings of =
me,=20
rather than of parent</DIV>
<DIV><BR></DIV>
<DIV><FONT face=3DArial size=3D2>Sorry, my __bobo_traverse__ method is =
working,=20
the PARENTS stack is exactly as I would hope, with my module as the =
parent of=20
the category, rather than the root.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Here's the whole story:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>/</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
index_html =20
(dtml method)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
index.html =20
(dtml method)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> category =
(Folder)</FONT></DIV>
<DIV><FONT face=3DArial=20
=
size=3D2> foo.html &n=
bsp; =20
(dtml method)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
blah =20
(Module)</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2> =20
category (Folder)</FONT></DIV>
<DIV><FONT face=3DArial=20
=
size=3D2> &nbs=
p;=20
header.html (dtml method)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
weather =20
(Category)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>/index_html:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> <dtml-var=20
index.html></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>/index.html:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> <dtml-var=20
standard_html_header></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> <dtml-if =
expr=3D"meta_type =3D=3D=20
'Category'"> <!-- true in cases of url like=20
/blah/weather --></FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
<dtml-call expr=3D"REQUEST.set('splevel', =
category)"></FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
</dtml-if></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> <dtml-with =
splevel=20
mapping></FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
<dtml-var header.html></FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
</dtml-with></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> <dtml-var=20
standard_html_footer></FONT></DIV>
<DIV> </DIV>
<DIV> </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 =
header.html. However, somehow it's getting the /category folder =
instead,=20
which doesn't have header.html.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Anyone understand why this is=20
happening?</FONT></DIV>
<DIV> </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=20
Kern</A> </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,=20
Modules (and their derivatives), and Categories. A normal =
setup might=20
look something like this:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>root</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
blab =20
(Module)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> weather=20
(Category)</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2> rain=20
(Category)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
sun=20
(Category)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> region=20
(Category)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I need to handle URLs like=20
/root/blab/weather. The problem is that I need =
weather.__of__(blab) on=20
the stack, rather than weather.__of__(root) on top. This is =
because=20
blab (in some cases) overrides default behaviors from =
root.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I thought the proper way to do this =
was by=20
adding a __bobo_traverse__ method to my Module, like =
this:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> def =
__bobo_traverse__(self,=20
REQUEST, name):<BR> =20
=
try:<BR>  =
;=20
parents =3D=20
=
REQUEST['PARENTS']<BR> &nb=
sp; =20
parent =3D=20
=
parents[-2]<BR> &nbs=
p; =20
if hasattr(parent,=20
=
name):<BR> &nb=
sp; =20
ob =3D getattr(parent,=20
=
name)<BR> &nbs=
p; =20
if ob.meta_type =3D=3D=20
=
'Category':<BR> &nbs=
p; =20
return=20
=
ob.aq_inner.__of__(self)<BR> =20
=
except:<BR> &n=
bsp;=20
pass</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2> =20
return getattr(self, name)<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </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> </DIV>
<DIV><FONT face=3DArial size=3D2>Basically, I'm trying to offer my =
siblings as=20
if they were my children, so if they fail to offer something, it =
will be=20
looked for in me, rather than my parent.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>-Randy</DIV></BLOCKQUOTE></BLOCKQUOTE></FONT></BODY></HTML>
------=_NextPart_000_1E90_01C05DD9.83B5F3C0--