1 | """Catalog tool columns updater setup handlers. |
---|
2 | """ |
---|
3 | from zope.component import adapts |
---|
4 | from zope.component import queryUtility |
---|
5 | |
---|
6 | from Products.ZCatalog.interfaces import IZCatalog |
---|
7 | from Products.GenericSetup.interfaces import ISetupEnviron |
---|
8 | from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter |
---|
9 | |
---|
10 | from quintagroup.catalogupdater.interfaces import ICatalogUpdater |
---|
11 | |
---|
12 | |
---|
13 | class CatalogUpdaterXMLAdapter(ZCatalogXMLAdapter): |
---|
14 | """XML im- and exporter for ZCatalog with |
---|
15 | support of columns updates |
---|
16 | """ |
---|
17 | |
---|
18 | adapts(IZCatalog, ISetupEnviron) |
---|
19 | |
---|
20 | def _initColumns(self, node): |
---|
21 | super(CatalogUpdaterXMLAdapter, self)._initColumns(node) |
---|
22 | import pdb;pdb.set_trace() |
---|
23 | updatecols = [] |
---|
24 | for child in node.childNodes: |
---|
25 | if child.nodeName != 'column': |
---|
26 | continue |
---|
27 | col = str(child.getAttribute('value')) |
---|
28 | if child.hasAttribute('update'): |
---|
29 | # Add the column to update list if it is there |
---|
30 | if col in self.context.schema()[:]: |
---|
31 | updatecols.append(col) |
---|
32 | continue |
---|
33 | |
---|
34 | # Update columns in catalog |
---|
35 | if len(updatecols) > 0: |
---|
36 | catalog = self.context |
---|
37 | |
---|
38 | self._logger.info('Updating %s columns for %s Catalog.' % ( |
---|
39 | updatecols, '/'.join(catalog.getPhysicalPaht())) ) |
---|
40 | |
---|
41 | cu = queryUtility(ICatalogUpdater, name='catalog_updater') |
---|
42 | cu.updateMetadata4All(catalog, updatecols) |
---|