[Zope] __getattr__ and getPhysicalRoot()

Michael Ruberto michael at dortronics.com
Fri Apr 30 14:41:57 EDT 2004


I have a very similar need. I require a list of objects from a folder in a
different "arm" of the directory tree. Last night I banged my head against
the desk for an hour and came up with this (this is from memory).

Python Script: getList (no args)

a[]
path = "/sub1/sub2/target_folder"
targFolder = context.restrictedTraverse(path)
for Item in targFolder.objectValues()
	a.append(item.getId())

a.sort
return a

DTML Document: target_folder_list

<dtml-in getList>
	<dtml-var sequence-item><br>
</dtml-in>

This worked fine for me and I hope it gives you some ideas. How valid and
legal it is to do this isn't something I can answer. A good idea I'll try
tonight is to modify this script so I can pass the Path as an argument and
return the absolute URL for use in a hyperlink.


Mike Ruberto
DORTRONICS SYSTEMS, INC
1668 Sag Harbor Tpke
Sag Harbor, NY  11963


-----Original Message-----
From: zope-bounces at zope.org [mailto:zope-bounces at zope.org] On Behalf Of
Stefan Bund
Sent: Friday, April 30, 2004 2:13 AM
To: zope at zope.org
Subject: Re: [Zope] __getattr__ and getPhysicalRoot()

Dieter Maurer <dieter at handshake.de> writes:
> You may have a look at my "Reference" product and
> see how I tackle a similar problem:
>
>   <http://www.dieter.handshake.de/pyprojects/zope>

Thanks. I already did that... you override __of__ instead of
__getattr__. But that will not work in my case. Some more details, of
what I wanted to accomplish:

I wanted to implement something which behaves like a
TransparendFolder, extending acquisition to another object not on the
direct acquisition path. But instead of placing a folder with
transparently to be acquired objects into a folder, I wanted to place
a link or reference to some other folder into the folder which would
transparently acquire the objects of that folder into the current
folder. This would enable me to do something like the 'multiple
inheritance' of classes using acquisition in such a way, that for any
folder I could explicitly list any 'base' folders to be acquired.

To explain further: I have already implemented a system to give every
page on my website an abstract interface. But at the moment, this
interface has to be reimplemented fully for each and every page. Often
page interfaces multiply inherit other interfaces (every page inherits
the main menu interface, others might inherit the news interface and
so on). It would be very nice instead of reimplementing the interfaces
for every folder or using some complicated acquisition path magic just
to import the implementation from somewhere else into the folder using
above link pattern.

I am now pretty convinced, that this is impossible using just the
TransparentFolderPatch, as this checks the attributes of the
transparent object at __getattr__ time and there is no acquisition
possible at that time. So I believe, I'll have to go the other route,
and implement a special folder type, which does what your Reference
Product does: add all the imported implementation folders to the
acquisition path in __of__.

I hope, my intent is clear now. If anyone has any idea, how to
implement my original link scheme, I'd appreciate a pointer ...

Stefan.

-- 
-- *DON'T* TRY TO REACH ME DIRECTLY AT ABOVE EMAIL ADDRESS. Any reply
-- received off-list at that address will be *silently* and
-- *unconditionally* dropped. You can attribute this inconvenience to
-- the proliferation of spammers on the Internet. I hope, you can
-- understand my position and accept my counter measures.

_______________________________________________
Zope maillist  -  Zope at zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )




More information about the Zope mailing list