The difference between getattr and restrictedTraverse

Tom Lazar lists at tomster.org
Sun Jun 10 10:35:58 UTC 2007


hi tim, hi martin, et. al.

just finally catching up on this list after the PIKtipi sprint, so  
i'm chiming in a bit late here...

On Jun 1, 2007, at 4:21 PM, Tim Hicks wrote:

> What I'm trying to do now is make it so that methods on my weblog  
> object
> will return lists of IWeblogEntry-ish objects that know what sort  
> of URL
> they should have.  That way, I can call IWeblog.getLazyEntries(),  
> which
> does a catalog search for appropriate IWeblogEntry objects, and then
> call absolute_url (or getURL) on each of the returned objects and have
> it return a blog-archive-ish URL rather than where it really lives.

IMHO this is not a good approach as it blurs the boundary between  
content and representation. why should a (weblog entry) object 'know'  
what its display url is? what if you change the mapping? you would  
have to change your code...

if you want to optimize the retrieval of this url via catalog brains,  
why not add a method 'pretty_url' (or somesuch) and add that to the  
catalog? this method would adapt the context to something that  
'knows' how to map the url and return the 'pretty' url.

incidentially i'm faced with a very similar problem in a client  
project at the moment (where we have a shop located in e.g. `/shops/ 
superstore` but want to present `/shops/europe/germany/berlin/ 
superstore`....)

also, i'm still interested in quills development ;-)

so perhaps we can work something out together how to handle this?

also, this would then make nice fodder for a howto/tutorial. i can  
imagine that this is a sort of problem that many product developers  
are faced with...

any input appreciated,

cheers,

tom

> If
> I understand correctly, this latter case has nothing to do with
> IPublishTraverse, hence my desire to wrap/proxy the brains/objects  
> with
> something that will give my the correct URL behaviour, and then just
> pass everything else through to the underlying object.  My attempt at
> implementing this is at
> <http://dev.plone.org/collective/browser/Quills/branches/maurits- 
> traversal/traversalfaker.py?rev=42942>.
>
> Does this approach make sense?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20070610/be664afd/attachment-0001.html>


More information about the Product-Developers mailing list