Changeset 2018 in products


Ignore:
Timestamp:
Mar 26, 2010 4:18:38 PM (14 years ago)
Author:
fenix
Message:

added compatibility with plone 2.5-3.3

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

Legend:

Unmodified
Added
Removed
  • quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/catalog.py

    r1928 r2018  
    11from zope.interface import Interface 
    22from zope.component import queryAdapter 
    3 from plone.indexer.decorator import indexer 
    43 
     4#for compatibility with older plone versions  
     5try: 
     6    from plone.indexer.decorator import indexer  
     7    IS_NEW = True 
     8except: 
     9    IS_NEW = False 
     10    class IDummyInterface:pass 
     11    class indexer: 
     12 
     13         def __init__(self, *interfaces): 
     14            self.interfaces = IDummyInterface, 
     15 
     16         def __call__(self, callable): 
     17             callable = lambda *args, **kw:None 
     18             callable.__component_adapts__ = self.interfaces 
     19             callable.__implemented__ = Interface 
     20             return callable 
     21     
    522from interfaces import ICanonicalPath 
    623from interfaces import ICanonicalLink 
     
    2340        return adapter.canonical_link 
    2441    return None 
     42 
     43#for compatibility with older plone versions  
     44if not IS_NEW: 
     45    from Products.CMFPlone.CatalogTool import registerIndexableAttribute 
     46    map(registerIndexableAttribute, ('canonical_path', 'canonical_link'), 
     47                                    (canonical_path, canonical_link)) 
  • quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py

    r1934 r2018  
    33from zope.testing import doctestunit 
    44from zope.component import testing 
    5 from zope.component import queryAdapter, queryMultiAdapter 
     5from zope.component import queryAdapter, queryMultiAdapter, getMultiAdapter 
    66from zope.schema.interfaces import InvalidValue 
    7 from plone.indexer.interfaces import IIndexableObject 
     7 
     8#for compatibility with older plone versions  
     9try: 
     10    from plone.indexer.interfaces import IIndexableObject 
     11    IS_NEW = True 
     12except: 
     13    from plone.app.content.interfaces import IIndexableObjectWrapper \ 
     14        as _old_IIndexableObjectWrapper 
     15    IS_NEW = False 
     16 
     17 
    818from Testing import ZopeTestCase as ztc 
    919 
     
    4050        self.logout() 
    4151 
     52    def get_indexable_wrapper(self, obj): 
     53        if IS_NEW: 
     54            wrapper = None 
     55            if not IIndexableObject.providedBy(obj): 
     56                wrapper = queryMultiAdapter((obj, self.catalog), IIndexableObject) 
     57        else: 
     58            wf = getattr(self.portal, 'portal_workflow', None) 
     59            if wf is not None: 
     60                vars = wf.getCatalogVariablesFor(obj) 
     61            else: 
     62                vars = {} 
     63            wrapper = getMultiAdapter((obj, self.portal), _old_IIndexableObjectWrapper) 
     64            wrapper.update(vars) 
     65             
     66        return wrapper and wrapper or obj 
     67 
    4268    def testForPortal(self): 
    43         wrapper = queryMultiAdapter((self.portal, self.catalog), IIndexableObject) 
     69        wrapper = self.get_indexable_wrapper(self.portal) 
    4470        self.assertFalse(wrapper is None, "No indexer registered for portal object") 
    4571 
    4672    def testForAT(self): 
    47         wrapper = queryMultiAdapter((self.my_doc, self.catalog), IIndexableObject) 
     73        wrapper = self.get_indexable_wrapper(self.my_doc) 
    4874        self.assertFalse(wrapper is None, "No indexer registered for document object") 
    4975 
    5076    def testCanonicalPathForPortal(self): 
    51         wrapper = queryMultiAdapter((self.portal, self.catalog), IIndexableObject) 
     77        wrapper =  self.get_indexable_wrapper(self.portal) 
    5278        self.assertTrue(hasattr(wrapper, 'canonical_path'), 
    5379            "'canonical_path' attribute not accessible with indexer wrapper for portal object") 
    5480 
    5581    def testCanonicalPathForAT(self): 
    56         wrapper = queryMultiAdapter((self.my_doc, self.catalog), IIndexableObject) 
     82        wrapper = self.get_indexable_wrapper(self.my_doc) 
    5783        self.assertTrue(hasattr(wrapper, 'canonical_path'), 
    5884            "'canonical_path' attribute not accessible with indexer wrapper for Document object") 
    5985 
    6086    def testCanonicalLinkForPortal(self): 
    61         wrapper = queryMultiAdapter((self.portal, self.catalog), IIndexableObject) 
     87        wrapper = self.get_indexable_wrapper(self.portal) 
    6288        self.assertTrue(hasattr(wrapper, 'canonical_link'), 
    6389            "'canonical_link' attribute not accessible with indexer wrapper for portal object") 
    6490 
    6591    def testCanonicalLinkForAT(self): 
    66         wrapper = queryMultiAdapter((self.my_doc, self.catalog), IIndexableObject) 
     92        wrapper = self.get_indexable_wrapper(self.my_doc) 
    6793        self.assertTrue(hasattr(wrapper, 'canonical_link'), 
    6894            "'canonical_link' attribute not accessible with indexer wrapper for Document object") 
Note: See TracChangeset for help on using the changeset viewer.