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

Last change on this file since 1759 was 1759, checked in by mylan, 14 years ago

Added GS catalogupdater import handler and XMLAdapter for catalogupdate.xml files in the GS profile

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1"""Catalog tool columns updater setup handlers.
2"""
3from zope.component import adapts
4from zope.component import queryUtility
5
6from Products.CMFCore.utils import getToolByName
7from Products.GenericSetup.utils import importObjects
8from Products.GenericSetup.utils import XMLAdapterBase
9from Products.GenericSetup.interfaces import ISetupEnviron
10
11from quintagroup.catalogupdater.interfaces import IUpdatableCatalog
12
13
14class CatalogUpdaterXMLAdapter(XMLAdapterBase):
15    """XML Catalog columns updater for CatalogTool.
16    """
17
18    adapts(IUpdatableCatalog, ISetupEnviron)
19
20    _LOGGER_ID = 'catalogupdater'
21
22    name = 'catalogupdater'
23
24    def _exportNode(self):
25        """Export the object as a DOM node.
26        """
27        return ''
28
29    def _importNode(self, node):
30        """Import the object from the DOM node.
31        """
32        self._updateColumns(node)
33        self._logger.info('Catalog columns updated.')
34
35
36    def _updateColumns(self, node):
37        columns = []
38        for child in node.childNodes:
39            if child.nodeName != 'column':
40                continue
41            col = str(child.getAttribute('value')).strip()
42            columns.append(col)
43
44        # Update columns in catalog
45        if len(columns) > 0:
46
47            catalog = self.context
48
49            self._logger.info('Updating %s columns for %s Catalog.' % (
50                columns, '/'.join(catalog.getPhysicalPaht())) )
51
52            cu = queryUtility(ICatalogUpdater, name='catalog_updater')
53            cu.updateMetadata4All(catalog, columns)
54
55
56def updateCatalogColumns(context):
57    """Update catalog columns with catalog_updater tool.
58    """
59    site = context.getSite()
60    tool = getToolByName(site, 'portal_catalog')
61
62    importObjects(tool, '', context)
Note: See TracBrowser for help on using the repository browser.