george hu wrote:
> As BFG document stated, all the object instances of model graph in 
> Traversal must have __name__ and __parent__ attribute, and they should 
> be hierarchically "linked". As the traversal wiki example reveals, page 
> objects are implementing this rule. But when I look at the source code 
> of bfgsite,  I can't see the rule is followed. The WebSite is the root 
> object so it has __name__=__parent__=None, but none of it's sub objects 
> (PasteBin/PasteEntry, TutorialBin/Tutorial) has code of assigning 
> __name__ and __parent__, neither in object initializing nor object 
> adding part, and I don't find the usage of traversalwrapper as mentioned 
> in document, in which case we can avoid mange location aware objects "by 
> hand". So is it a rule of "Must"?

It's not a complete must, but if you want the repoze.bfg.url.model_url API to 
work, these attribute must be assigned.

bfgite uses repoze.folder.Folder, which assigns these attributes at __setitem__ 
time, that's why you don't see these assignments in the bfgsite package itself.

There's an alternate BFG "traverser" implementation which wraps traversed 
objects in proxies.  It prevents you from needing to think about this, at the 
cost of decreased performance and more dependencies: 
http://pypi.python.org/pypi/repoze.bfg.traversalwrapper

- C

_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to