source: products/quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/catalog.py @ 2125

Last change on this file since 2125 was 2125, checked in by mylan, 14 years ago

#146: Fix indexable attribute registration for plone < 3.3

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1from zope.interface import Interface
2from zope.component import queryAdapter
3
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.__component_adapts__ = self.interfaces
18             callable.__implemented__ = Interface
19             return callable
20   
21from interfaces import ICanonicalPath
22from interfaces import ICanonicalLink
23
24@indexer(Interface)
25def canonical_path(obj, **kwargs):
26    """Return canonical_path property for the object.
27    """
28    adapter = queryAdapter(obj, interface=ICanonicalPath)
29    if adapter:
30        return adapter.canonical_path
31    return None
32
33@indexer(Interface)
34def canonical_link(obj, **kwargs):
35    """Return canonical_link property for the object.
36    """
37    adapter = queryAdapter(obj, interface=ICanonicalLink)
38    if adapter:
39        return adapter.canonical_link
40    return None
41
42#for compatibility with older plone versions
43if not IS_NEW:
44    from Products.CMFPlone.CatalogTool import registerIndexableAttribute
45    map(registerIndexableAttribute, ('canonical_path', 'canonical_link'),
46                                    (canonical_path, canonical_link))
Note: See TracBrowser for help on using the repository browser.