source: products/quintagroup.transmogrify.simpleblog2quills/trunk/quintagroup/transmogrify/simpleblog2quills/itemmanipulator.py

Last change on this file was 1490, checked in by koval, 14 years ago

renaming all references of quintagroup.transmogrifier.simpleblog2quills

File size: 1.6 KB
Line 
1from zope.interface import classProvides, implements
2from zope.component import queryAdapter
3
4from collective.transmogrifier.interfaces import ISection, ISectionBlueprint
5from collective.transmogrifier.utils import defaultMatcher
6
7from quintagroup.transmogrify.simpleblog2quills.interfaces import \
8    IItemManipulator, IExportItemManipulator, IImportItemManipulator
9
10class ItemManipulatorSection(object):
11    classProvides(ISectionBlueprint)
12    implements(ISection)
13
14    def __init__(self, transmogrifier, name, options, previous):
15        self.previous = previous
16        self.context = transmogrifier.context
17
18        self.pathkey = defaultMatcher(options, 'path-key', name, 'path')
19
20        # 'type' options specifies adapter interface
21        type_ = options.get('type', 'general')
22        if type_ == 'general':
23            self.interface = IItemManipulator
24        elif type_ == 'export':
25            self.interface = IExportItemManipulator
26        elif type_ == 'import':
27            self.interface = IImportItemManipulator
28        else:
29            self.interface = None
30
31    def __iter__(self):
32        for item in self.previous:
33            pathkey = self.pathkey(*item.keys())[0]
34
35            if not (pathkey and self.interface is not None):
36                yield item; continue
37
38            path = item[pathkey]
39            obj = self.context.unrestrictedTraverse(path, None)
40            if obj is None:         # path doesn't exist
41                yield item; continue
42
43            adapter = queryAdapter(obj, self.interface, name='')
44            if adapter:
45                item = adapter(item, path=pathkey)
46
47            yield item
Note: See TracBrowser for help on using the repository browser.