Changeset 1755 in products for quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/utility.py
- Timestamp:
- Feb 16, 2010 4:04:07 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/utility.py
r1754 r1755 1 import logging 1 import logging, types 2 2 from zope.interface import implements 3 3 from zope.component import queryMultiAdapter … … 22 22 implements(ICatalogUpdater) 23 23 24 def validate(self, cat, col ):24 def validate(self, cat, cols): 25 25 # Validate catalog and column name 26 AVAIL_COLTYPES = list(types.StringTypes) + [types.ListType, types.TupleType] 27 26 28 _cat = getattr(cat, '_catalog', None) 27 28 29 if _cat is None: 29 30 raise AttributeError("%s - is not ZCatalog based catalog" % cat) 30 31 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 33 44 34 45 def getWrapedObject(self, obj, portal, catalog): … … 49 60 50 61 51 def updateMetadata4All(self, catalog, column ):62 def updateMetadata4All(self, catalog, columns): 52 63 """ Look into appropriate method of ICatalogUpdate interface 53 64 """ 54 self.validate(catalog, column)55 65 56 _catalog = catalog._catalog 66 _catalog, columns = self.validate(catalog, columns) 67 57 68 portal = getToolByName(catalog, 'portal_url').getPortalObject() 58 69 root = aq_parent(portal) … … 60 71 data = _catalog.data 61 72 schema = _catalog.schema 62 indx = schema[column]63 73 paths = _catalog.paths 64 74 … … 71 81 obj = self.getWrapedObject(obj, portal, catalog) 72 82 except: 73 LOG.error('update _metadata_columncould not resolve '83 LOG.error('updateMetadata4All could not resolve ' 74 84 'an object from the uid %r.' % obj_uid) 75 85 continue 76 86 77 # calculate the column value78 87 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 81 95 82 # update metadata value 83 mdlist[indx] = attr 96 # Update catalog record 84 97 data[rid] = tuple(mdlist) 85 98
Note: See TracChangeset
for help on using the changeset viewer.