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

Last change on this file since 1760 was 1760, checked in by mylan, 14 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
RevLine 
[1759]1"""Catalog tool columns updater setup handlers.
2"""
3from zope.component import adapts
4from zope.component import queryUtility
5
[1760]6from Products.ZCatalog.interfaces import IZCatalog
[1759]7from Products.GenericSetup.interfaces import ISetupEnviron
[1760]8from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter
[1759]9
[1760]10from quintagroup.catalogupdater.interfaces import ICatalogUpdater
[1759]11
12
[1760]13class CatalogUpdaterXMLAdapter(ZCatalogXMLAdapter):
14    """XML im- and exporter for ZCatalog with
15       support of columns updates
[1759]16    """
17
[1760]18    adapts(IZCatalog, ISetupEnviron)
[1759]19
[1760]20    def _initColumns(self, node):
21        super(CatalogUpdaterXMLAdapter, self)._initColumns(node)
22        import pdb;pdb.set_trace()
23        updatecols = []
[1759]24        for child in node.childNodes:
25            if child.nodeName != 'column':
26                continue
[1760]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
[1759]33
34        # Update columns in catalog
[1760]35        if len(updatecols) > 0:
[1759]36            catalog = self.context
37
38            self._logger.info('Updating %s columns for %s Catalog.' % (
[1760]39                updatecols, '/'.join(catalog.getPhysicalPaht())) )
[1759]40
41            cu = queryUtility(ICatalogUpdater, name='catalog_updater')
[1760]42            cu.updateMetadata4All(catalog, updatecols)
Note: See TracBrowser for help on using the repository browser.