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

Last change on this file since 3146 was 3146, checked in by vmaksymiv, 13 years ago

pyflakes fixes

  • 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    indexer
8    IS_NEW = True
9except:
10    IS_NEW = False
11
12    class IDummyInterface:
13        pass
14
15    class indexer:
16
17        def __init__(self, *interfaces):
18            self.interfaces = IDummyInterface,
19
20        def __call__(self, callable):
21            callable.__component_adapts__ = self.interfaces
22            callable.__implemented__ = Interface
23            return callable
24
25from interfaces import ICanonicalPath
26from interfaces import ICanonicalLink
27
28
29@indexer(Interface)
30def canonical_path(obj, **kwargs):
31    """Return canonical_path property for the object.
32    """
33    adapter = queryAdapter(obj, interface=ICanonicalPath)
34    if adapter:
35        return adapter.canonical_path
36    return None
37
38
39@indexer(Interface)
40def canonical_link(obj, **kwargs):
41    """Return canonical_link property for the object.
42    """
43    adapter = queryAdapter(obj, interface=ICanonicalLink)
44    if adapter:
45        return adapter.canonical_link
46    return None
47
48#for compatibility with older plone versions
49if not IS_NEW:
50    from Products.CMFPlone.CatalogTool import registerIndexableAttribute
51    map(registerIndexableAttribute, ('canonical_path', 'canonical_link'),
52                                    (canonical_path, canonical_link))
Note: See TracBrowser for help on using the repository browser.