Personal tools
You are here: Home Weblog Archive 2006 October 21 Custom traversing with Five and ITraversable
Document Actions
  • Send this page to somebody
  • Print this page
  • Add Bookmarklet

Custom traversing with Five and ITraversable

by tibi last modified 2006-10-21 08:23
Filed Under:

This blog already contains a technique on how to customize the traversal to return any object, using __bobo_traverse__

A more simple, modern and elegant way of doing achieving this is detailed in the newly released ImageRepository. Basically, it uses an adapter to change the implementation for ITraversable when the traversal is done on an object implementing a marker interface. I've lifted the relevant code and pasted it below, but the original sources should be consulted for reference.

class ImageRepositoryTraversable(FiveTraversable):
    """Intercepts traversal for IImageRepository, but only for 'tags'.
    Everything else is left untouched.
    """

    def traverse(self, name, furtherPath):
                 return some_obj

Next, the zcml configuration file contains:

  <five:traversable class=".content.ImageRepository.ImageRepository" />

  <adapter
      for=".interfaces.IImageRepository"
      provides="zope.app.traversing.interfaces.ITraversable"
      factory=".traversal.ImageRepositoryTraversable" />
Weblog
Atom
RDF
RSS 2.0
Powered by Quills
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: