Changeset 3142 in products for quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/utility.py
- Timestamp:
- Apr 19, 2011 9:06:50 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/utility.py
r1981 r3142 1 import logging, types 1 import logging 2 import types 2 3 import transaction 3 4 from zope.interface import implements … … 6 7 7 8 from Missing import MV 8 from Acquisition import aq_inner9 9 from Acquisition import aq_parent 10 10 … … 18 18 as _old_IIndexableObjectWrapper 19 19 IS_NEW = False 20 else: 20 else: 21 21 IS_NEW = True 22 22 … … 33 33 def validate(self, cat, cols): 34 34 # Validate catalog and column name 35 AVAIL_COLTYPES = list(types.StringTypes) + [types.ListType, types.TupleType] 35 AVAIL_COLTYPES = list(types.StringTypes) + [types.ListType, 36 types.TupleType] 36 37 37 38 _cat = getattr(cat, '_catalog', None) … … 40 41 41 42 if not type(cols) in AVAIL_COLTYPES: 42 raise TypeError("'columns' parameter must be one of the following" \43 " types: %s" % AVAIL_COLTYPES)43 raise TypeError("'columns' parameter must be one of the " \ 44 "following types: %s" % AVAIL_COLTYPES) 44 45 # Normalize columns 45 46 if type(cols) in types.StringTypes: 46 cols = [cols, ]47 cols = [cols, ] 47 48 # Check is every column present in the catalog 48 49 for col in cols: 49 if not _cat.schema.has_key(col): 50 raise AttributeError("'%s' - not presented column in %s catalog " % (col, cat)) 50 if not col in _cat.schema: 51 raise AttributeError("'%s' - not presented column in " \ 52 "%s catalog " % (col, cat)) 51 53 52 54 return _cat, cols 53 54 55 55 56 def getWrappedObjectNew(self, obj, portal, catalog): … … 57 58 wrapper = None 58 59 if not IIndexableObject.providedBy(obj): 59 # This is the CMF 2.2 compatible approach, which should be used going forward 60 wrapper = queryMultiAdapter((obj, catalog), IIndexableObject) 60 # This is the CMF 2.2 compatible approach, 61 # which should be used going forward 62 wrapper = queryMultiAdapter((obj, catalog), IIndexableObject) 61 63 return wrapper and wrapper or obj 62 64 … … 72 74 else: 73 75 vars = {} 74 76 75 77 w = getMultiAdapter((obj, portal), _old_IIndexableObjectWrapper) 76 78 w.update(vars) 77 79 78 80 return w 79 80 81 81 82 def updateMetadata4All(self, catalog, columns): … … 87 88 portal = getToolByName(catalog, 'portal_url').getPortalObject() 88 89 root = aq_parent(portal) 89 90 90 91 data = _catalog.data 91 92 schema = _catalog.schema 92 93 paths = _catalog.paths 93 getWrappedObject = IS_NEW and self.getWrappedObjectNew or self.getWrappedObjectOld 94 getWrappedObject = (IS_NEW and self.getWrappedObjectNew 95 or self.getWrappedObjectOld) 94 96 # For subtransaction support 95 97 threshold = getattr(catalog, 'threshold', 10000) … … 112 114 for column in columns: 113 115 # calculate the column value 114 attr=getattr(obj, column, MV) 115 if(attr is not MV and safe_callable(attr)): attr=attr() 116 attr = getattr(obj, column, MV) 117 if (attr is not MV and safe_callable(attr)): 118 attr = attr() 116 119 # Update metadata value 117 120 indx = schema[column] … … 134 137 _v_total = 0 135 138 LOG.info('commiting subtransaction') 136
Note: See TracChangeset
for help on using the changeset viewer.