Ignore:
Timestamp:
Feb 17, 2010 1:38:20 PM (14 years ago)
Author:
mylan
Message:

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

Location:
quintagroup.catalogupdater/trunk/quintagroup/catalogupdater
Files:
2 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/configure.zcml

    r1759 r1760  
    11<configure 
    22    xmlns="http://namespaces.zope.org/zope" 
    3     xmlns:five="http://namespaces.zope.org/five" 
    4     xmlns:genericsetup="http://namespaces.zope.org/genericsetup" 
    53    i18n_domain="quintagroup.catalogupdater"> 
    6  
    7     <include package=".exportimport" /> 
    84 
    95    <utility factory=".utility.CatalogUpdaterUtility" 
    106             name="catalog_updater" /> 
    117 
    12     <!-- Mark ZCatalog class with own interface for correct 
    13          working of GenericSetup import handler --> 
    14  
    15     <class class="Products.ZCatalog.ZCatalog.ZCatalog"> 
    16       <implements interface=".interfaces.IUpdatableCatalog" /> 
    17     </class> 
    18  
    19     <!-- register GenericSetup profile --> 
    20     <genericsetup:registerProfile 
    21       name="default" 
    22       title="quintagroup.catalogupdater" 
    23       directory="profiles/default" 
    24       description="Register Catalog Updater import step handler [quintagroup.catalogupdater]" 
    25       provides="Products.GenericSetup.interfaces.EXTENSION" 
    26       /> 
    27      
    28  
    298</configure>  
  • quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/catalogupdater.py

    r1759 r1760  
    44from zope.component import queryUtility 
    55 
    6 from Products.CMFCore.utils import getToolByName 
    7 from Products.GenericSetup.utils import importObjects 
    8 from Products.GenericSetup.utils import XMLAdapterBase 
     6from Products.ZCatalog.interfaces import IZCatalog 
    97from Products.GenericSetup.interfaces import ISetupEnviron 
     8from Products.GenericSetup.ZCatalog.exportimport import ZCatalogXMLAdapter 
    109 
    11 from quintagroup.catalogupdater.interfaces import IUpdatableCatalog 
     10from quintagroup.catalogupdater.interfaces import ICatalogUpdater 
    1211 
    1312 
    14 class CatalogUpdaterXMLAdapter(XMLAdapterBase): 
    15     """XML Catalog columns updater for CatalogTool. 
     13class CatalogUpdaterXMLAdapter(ZCatalogXMLAdapter): 
     14    """XML im- and exporter for ZCatalog with 
     15       support of columns updates 
    1616    """ 
    1717 
    18     adapts(IUpdatableCatalog, ISetupEnviron) 
     18    adapts(IZCatalog, ISetupEnviron) 
    1919 
    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 = [] 
     20    def _initColumns(self, node): 
     21        super(CatalogUpdaterXMLAdapter, self)._initColumns(node) 
     22        import pdb;pdb.set_trace() 
     23        updatecols = [] 
    3824        for child in node.childNodes: 
    3925            if child.nodeName != 'column': 
    4026                continue 
    41             col = str(child.getAttribute('value')).strip() 
    42             columns.append(col) 
     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 
    4333 
    4434        # Update columns in catalog 
    45         if len(columns) > 0: 
    46  
     35        if len(updatecols) > 0: 
    4736            catalog = self.context 
    4837 
    4938            self._logger.info('Updating %s columns for %s Catalog.' % ( 
    50                 columns, '/'.join(catalog.getPhysicalPaht())) ) 
     39                updatecols, '/'.join(catalog.getPhysicalPaht())) ) 
    5140 
    5241            cu = queryUtility(ICatalogUpdater, name='catalog_updater') 
    53             cu.updateMetadata4All(catalog, columns) 
    54  
    55  
    56 def 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) 
     42            cu.updateMetadata4All(catalog, updatecols) 
Note: See TracChangeset for help on using the changeset viewer.