Changeset 3142 in products
- Timestamp:
- Apr 19, 2011 9:06:50 AM (13 years ago)
- Location:
- quintagroup.catalogupdater/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/catalogupdater.py
r1761 r3142 37 37 38 38 self._logger.info('Updating %s columns for %s Catalog.' % ( 39 updatecols, '/'.join(catalog.getPhysicalPath())) 39 updatecols, '/'.join(catalog.getPhysicalPath()))) 40 40 41 41 cu = queryUtility(ICatalogUpdater, name='catalog_updater') -
quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/tests/test_catalogupdate.py
r1981 r3142 39 39 """ % (PLONEFOUR and '<object name="old_plexicon" remove="True"/>' or \ 40 40 '<object name="foo_vocabulary" remove="True"/>') 41 42 41 43 42 … … 47 46 def updateMetadata4All(self, catalog, columns): 48 47 self._logger.info("%s:%s" % (catalog.id, columns)) 49 48 50 49 51 50 class CatalogUpdaterZCMLLayer(test_exportimport.ZCatalogXMLAdapterTests.layer): … … 65 64 66 65 def _getTargetClass(self): 67 from quintagroup.catalogupdater.exportimport.catalogupdater import CatalogUpdaterXMLAdapter 66 from quintagroup.catalogupdater.exportimport.catalogupdater \ 67 import CatalogUpdaterXMLAdapter 68 68 return CatalogUpdaterXMLAdapter 69 69 … … 78 78 def getLastMessage(self): 79 79 messages = getattr(self.logger, '_messages', []) 80 return messages[-1] or [None, ]*380 return messages[-1] or [None, ] * 3 81 81 82 82 def test_body_set_update(self): … … 90 90 91 91 message = self.getLastMessage() 92 self.assertEqual( message[-1], "foo_catalog:['eggs', 'spam']", 93 "Not updated columns in catalog" ) 92 self.assertEqual(message[-1], "foo_catalog:['eggs', 'spam']", 93 "Not updated columns in catalog") 94 94 95 95 96 def test_suite(): -
quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/interfaces.py
r1759 r3142 1 1 from zope.interface import Interface 2 2 3 3 4 class IUpdatableCatalog(Interface): … … 5 6 exportimport handler 6 7 """ 8 7 9 8 10 class ICatalogUpdater(Interface): … … 17 19 metadata, which must be updated. 18 20 """ 19 -
quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/tests.py
r1866 r3142 5 5 from zope.component import queryUtility 6 6 from zope.component import provideAdapter 7 8 from Testing import ZopeTestCase as ztc9 7 10 8 from Products.Five import zcml … … 37 35 ptc.setupPloneSite() 38 36 37 39 38 class TestUtility(TestCase): 40 39 41 40 def afterSetUp(self): 42 41 self.loginAsPortalOwner() 43 self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') 42 self.my_doc = makeContent(self.portal, portal_type='Document', 43 id='my_doc') 44 44 self.catalog = getToolByName(self.portal, 'portal_catalog') 45 45 self.logout() … … 51 51 self.catalog.addColumn('test_column') 52 52 53 54 53 def addIndexerNew(self): 55 54 @indexer(Interface) … … 58 57 provideAdapter(test_column, name='test_column') 59 58 60 61 59 def addIndexerOld(self): 62 60 def test_column(obj, portal, **kwargs): 63 61 return obj.id 64 62 registerIndexableAttribute("test_column", test_column) 65 66 63 67 64 def testSingleColumnUpdate(self): … … 93 90 self.assertTrue(mydoc.Title == "My document", mydoc.Title) 94 91 95 self.my_doc.setTitle('New my document') # catalog not updated92 self.my_doc.setTitle('New my document') # catalog not updated 96 93 cu = queryUtility(ICatalogUpdater, name="catalog_updater") 97 94 cu.updateMetadata4All(self.catalog, 'test_column') … … 100 97 self.assertTrue(mydoc.Title == 'My document', 101 98 "Other metadata updated: Title='%s'" % mydoc.Title) 102 103 99 104 100 def testAllRecordsUpdate(self): … … 110 106 num_recs = len(self.catalog._catalog.data) 111 107 allcat = self.catalog.unrestrictedSearchResults(path='/') 112 num_updated = sum([1 for b in allcat if b.test_column ==b.id])108 num_updated = sum([1 for b in allcat if b.test_column == b.id]) 113 109 114 110 self.assertTrue(num_updated == num_recs, "Only %d records updated, " \ 115 111 "must be - %d" % (num_updated, num_recs)) 116 117 112 118 113 def testTransaction(self): … … 121 116 # savepoint patch 122 117 global sp_commits 123 sp_commits = 1 # Starts from 1 to count last commit118 sp_commits = 1 # Starts from 1 to count last commit 124 119 orig_trsp = transaction.savepoint 120 125 121 def dummy_savepoint(*args, **kwargs): 126 122 global sp_commits … … 132 128 num_recs = len(self.catalog.unrestrictedSearchResults(path='/')) 133 129 num_subcommits = 3 134 self.catalog.threshold = num_recs /num_subcommits130 self.catalog.threshold = num_recs / num_subcommits 135 131 136 132 cu = queryUtility(ICatalogUpdater, name="catalog_updater") 137 133 cu.updateMetadata4All(self.catalog, 'test_column') 138 134 139 self.assertTrue(sp_commits == num_subcommits, 140 " Wrong number of transaction subcommits: actual:%d, must be: %d" % (141 sp_commits,num_subcommits))135 self.assertTrue(sp_commits == num_subcommits, "Wrong number of " \ 136 "transaction subcommits: actual:%d, must be: %d" % (sp_commits, 137 num_subcommits)) 142 138 143 139 transaction.savepoint = orig_trsp 144 145 140 146 141 -
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 -
quintagroup.catalogupdater/trunk/setup.py
r1982 r3142 9 9 long_description=open("README.txt").read() + "\n" + 10 10 open(os.path.join("docs", "HISTORY.txt")).read(), 11 # Get more strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers12 11 classifiers=[ 13 12 "Framework :: Plone",
Note: See TracChangeset
for help on using the changeset viewer.