Changeset 1755 in products


Ignore:
Timestamp:
Feb 16, 2010 4:04:07 PM (14 years ago)
Author:
mylan
Message:

Update utility, and interface for updating list of columns in catalog

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

Legend:

Unmodified
Added
Removed
  • quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/interfaces.py

    r1754 r1755  
    33class ICatalogUpdater(Interface): 
    44 
    5     def updateMetadata4All(catalog, column): 
    6         """ Update only the column metadata in the catalog 
    7             for all records 
     5    def updateMetadata4All(catalog, columns): 
     6        """ Update metadata in the *catalog* for each column 
     7            in the *columns* list for all records. 
     8 
     9              * catalog - ZCatalog descendent catalog; 
     10              * columns - list of metadata names, or 
     11                          string with name of single 
     12                          metadata, which must be updated. 
    813        """ 
    914 
  • quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/utility.py

    r1754 r1755  
    1 import logging 
     1import logging, types 
    22from zope.interface import implements 
    33from zope.component import queryMultiAdapter 
     
    2222    implements(ICatalogUpdater) 
    2323 
    24     def validate(self, cat, col): 
     24    def validate(self, cat, cols): 
    2525        # Validate catalog and column name 
     26        AVAIL_COLTYPES = list(types.StringTypes) + [types.ListType, types.TupleType] 
     27 
    2628        _cat = getattr(cat, '_catalog', None) 
    27  
    2829        if _cat is None: 
    2930            raise AttributeError("%s - is not ZCatalog based catalog" % cat) 
    3031 
    31         if not _cat.schema.has_key(col): 
    32             raise AttributeError("'%s' - not presented column in %s catalog " % (col, cat)) 
     32        if not type(cols) in AVAIL_COLTYPES: 
     33            raise TypeError("'columns' parameter must be one of the following " \ 
     34                "types: %s" % AVAIL_COLTYPES) 
     35        # Normalize columns 
     36        if type(cols) in types.StringTypes: 
     37            cols = [cols,] 
     38        # Check is every column present in the catalog 
     39        for col in cols: 
     40            if not _cat.schema.has_key(col): 
     41                raise AttributeError("'%s' - not presented column in %s catalog " % (col, cat)) 
     42 
     43        return _cat, cols 
    3344 
    3445    def getWrapedObject(self, obj, portal, catalog): 
     
    4960 
    5061 
    51     def updateMetadata4All(self, catalog, column): 
     62    def updateMetadata4All(self, catalog, columns): 
    5263        """ Look into appropriate method of ICatalogUpdate interface 
    5364        """ 
    54         self.validate(catalog, column) 
    5565 
    56         _catalog = catalog._catalog 
     66        _catalog, columns = self.validate(catalog, columns) 
     67 
    5768        portal = getToolByName(catalog, 'portal_url').getPortalObject() 
    5869        root = aq_parent(portal) 
     
    6071        data = _catalog.data 
    6172        schema = _catalog.schema 
    62         indx = schema[column] 
    6373        paths = _catalog.paths 
    6474 
     
    7181                obj = self.getWrapedObject(obj, portal, catalog) 
    7282            except: 
    73                 LOG.error('update_metadata_column could not resolve ' 
     83                LOG.error('updateMetadata4All could not resolve ' 
    7484                          'an object from the uid %r.' % obj_uid) 
    7585                continue 
    7686 
    77             # calculate the column value 
    7887            mdlist = list(md) 
    79             attr=getattr(obj, column, MV) 
    80             if(attr is not MV and safe_callable(attr)): attr=attr() 
     88            for column in columns: 
     89                # calculate the column value 
     90                attr=getattr(obj, column, MV) 
     91                if(attr is not MV and safe_callable(attr)): attr=attr() 
     92                # Update metadata value 
     93                indx = schema[column] 
     94                mdlist[indx] = attr 
    8195 
    82             # update metadata value 
    83             mdlist[indx] = attr 
     96            # Update catalog record 
    8497            data[rid] = tuple(mdlist) 
    8598 
Note: See TracChangeset for help on using the changeset viewer.