source: products/quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/sitewalker.py @ 275

Last change on this file since 275 was 275, checked in by mylan, 18 years ago

Removed file/folder

File size: 1.2 KB
Line 
1from zope.interface import classProvides, implements
2
3from collective.transmogrifier.interfaces import ISection, ISectionBlueprint
4
5from Products.CMFCore.interfaces import IFolderish
6from Products.Archetypes.interfaces import IBaseFolder
7
8class SiteWalkerSection(object):
9    classProvides(ISectionBlueprint)
10    implements(ISection)
11
12    def __init__(self, transmogrifier, name, options, previous):
13        self.previous = previous
14        self.context = transmogrifier.context
15
16    def walk(self, obj):
17        if IFolderish.providedBy(obj) or IBaseFolder.providedBy(obj):
18            contained = [(k, v.getPortalTypeName()) for k, v in obj.contentItems()]
19            yield obj, tuple(contained)
20            for v in obj.contentValues():
21                for x in self.walk(v):
22                    yield x
23        else:
24            yield obj, ()
25
26    def __iter__(self):
27        for item in self.previous:
28            yield item
29
30        for obj, contained in self.walk(self.context):
31            item = {
32                '_path': '/'.join(obj.getPhysicalPath()[2:]),
33                '_type': obj.getPortalTypeName(),
34            }
35            if contained:
36                item['_entries'] = contained
37            yield item
38
Note: See TracBrowser for help on using the repository browser.