[Zope] siblings of me, rather than of parent
Randall Kern
randy@teamkern.net
Sun, 3 Dec 2000 20:08:32 -0800
This is a multi-part message in MIME format.
------=_NextPart_000_1CF8_01C05D64.CFB7B5D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
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)
But that doesn't seem to change anything, although it does perform the =
return (and doesn't throw any exceptions.)
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.
Thanks,
-Randy
------=_NextPart_000_1CF8_01C05D64.CFB7B5D0
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>My site has two main classes of =
objects, Modules=20
(and their derivatives), and Categories. A normal setup might 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 =
(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 =
(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 the=20
stack, rather than weather.__of__(root) on top. This is because =
blab (in=20
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 adding a=20
__bobo_traverse__ method to my Module, like this:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> def =
__bobo_traverse__(self, REQUEST,=20
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 =
ob.aq_inner.__of__(self)<BR> =20
except:<BR> &n=
bsp;=20
pass</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2> return=20
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, although=20
it does perform the return (and doesn't throw any =
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 if=20
they were my children, so if they fail to offer something, it will be =
looked for=20
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 size=3D2>-Randy</DIV></FONT></BODY></HTML>
------=_NextPart_000_1CF8_01C05D64.CFB7B5D0--