• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 35. Changing Traversal Behavior > Step 2: Creating the Traverser

Step 2: Creating the Traverser

Now you have a new content type, but it does not do anything special. You have to implement the special traverser for the non-case-sensitive folder. Luckily, you do not have to implement a new container traverser from scratch; you can just use the standard ContainerTraverser class and replace the publishTraverse() method to be a bit more flexible and ignore the case of the item names. In the __init__.py file, you add the following traverser implementation:

01 from zope.publisher.interfaces import NotFound
02
03 from zope.app import zapi
04 from zope.app.container.traversal import ContainerTraverser
05
06 class CaseInsensitiveFolderTraverser(ContainerTraverser):
07
08     __used_for__ = ICaseInsensitiveFolder
09
10     def publishTraverse(self, request, name):
11         """See zope.publisher.interfaces.browser.IBrowserPublisher"""
12         subob = self._guessTraverse(name) 
13         if subob is None:
14             view = zapi.queryView(self.context, name, request)
15             if view is not None:
16                 return view
17
18             raise NotFound(self.context, name, request)
19
20         return subob
21
22     def _guessTraverse(self, name):
23         for key in self.context.keys():
24             if key.lower() == name.lower():
25                 return self.context[key]
26         return None


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint