source: products/quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/catalogupdater.py @ 1760

Last change on this file since 1760 was 1760, checked in by mylan, 10 years ago

Refactoring XMLAdapter - override existent ZCatalog XMLAdaptor with *update* attribute for *column* tag

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1"""Catalog tool columns updater setup handlers.
2"""
3from zope.component import adapts
4from zope.component import queryUtility
5
6from Products.ZCatalog.interfaces import IZCatalog
7from Products.GenericSetup.interfaces import ISetupEnviron
8from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter
9
10from quintagroup.catalogupdater.interfaces import ICatalogUpdater
11
12
13class 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)
Note: See TracBrowser for help on using the repository browser.