1 | from xml.dom import minidom |
---|
2 | |
---|
3 | from zope.interface import classProvides, implements |
---|
4 | from zope.component import queryAdapter |
---|
5 | |
---|
6 | from collective.transmogrifier.interfaces import ISection, ISectionBlueprint |
---|
7 | from collective.transmogrifier.utils import defaultMatcher |
---|
8 | |
---|
9 | from quintagroup.transmogrifier.interfaces import IExportDataCorrector |
---|
10 | |
---|
11 | class ExportAdaptersSection(object): |
---|
12 | classProvides(ISectionBlueprint) |
---|
13 | implements(ISection) |
---|
14 | |
---|
15 | def __init__(self, transmogrifier, name, options, previous): |
---|
16 | self.previous = previous |
---|
17 | self.context = transmogrifier.context |
---|
18 | |
---|
19 | self.pathkey = defaultMatcher(options, 'path-key', name, 'path') |
---|
20 | self.datakey = defaultMatcher(options, 'data-key', name, 'data') |
---|
21 | |
---|
22 | def __iter__(self): |
---|
23 | for item in self.previous: |
---|
24 | pathkey = self.pathkey(*item.keys())[0] |
---|
25 | datakey = self.datakey(*item.keys())[0] |
---|
26 | |
---|
27 | if not (pathkey and datakey): |
---|
28 | yield item; continue |
---|
29 | |
---|
30 | path = item[pathkey] |
---|
31 | obj = self.context.unrestrictedTraverse(path, None) |
---|
32 | if obj is None: # path doesn't exist |
---|
33 | yield item; continue |
---|
34 | |
---|
35 | data_store = item[datakey] |
---|
36 | if not data_store: |
---|
37 | yield item; continue |
---|
38 | |
---|
39 | for name, data in data_store.items(): |
---|
40 | adapter = queryAdapter(obj, IExportDataCorrector, name) |
---|
41 | if adapter: |
---|
42 | data_store[name] = adapter(data) |
---|
43 | |
---|
44 | yield item |
---|