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

Last change on this file since 2111 was 2018, checked in by fenix, 14 years ago

added compatibility with plone 2.5-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 = lambda *args, **kw:None
18             callable.__component_adapts__ = self.interfaces
19             callable.__implemented__ = Interface
20             return callable
21   
22from interfaces import ICanonicalPath
23from interfaces import ICanonicalLink
24
25@indexer(Interface)
26def canonical_path(obj, **kwargs):
27    """Return canonical_path property for the object.
28    """
29    adapter = queryAdapter(obj, interface=ICanonicalPath)
30    if adapter:
31        return adapter.canonical_path
32    return None
33
34@indexer(Interface)
35def canonical_link(obj, **kwargs):
36    """Return canonical_link property for the object.
37    """
38    adapter = queryAdapter(obj, interface=ICanonicalLink)
39    if adapter:
40        return adapter.canonical_link
41    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))
Note: See TracBrowser for help on using the repository browser.