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
RevLine 
[1685]1from zope.interface import Interface
[782]2from zope.component import queryAdapter
3
[3145]4#for compatibility with older plone versions
[2018]5try:
[3145]6    from plone.indexer.decorator import indexer
[3146]7    indexer
[2018]8    IS_NEW = True
9except:
10    IS_NEW = False
[3145]11
12    class IDummyInterface:
13        pass
14
[2018]15    class indexer:
16
[3145]17        def __init__(self, *interfaces):
[2018]18            self.interfaces = IDummyInterface,
19
[3145]20        def __call__(self, callable):
21            callable.__component_adapts__ = self.interfaces
22            callable.__implemented__ = Interface
23            return callable
24
[782]25from interfaces import ICanonicalPath
[1928]26from interfaces import ICanonicalLink
[782]27
[3145]28
[1685]29@indexer(Interface)
30def canonical_path(obj, **kwargs):
[782]31    """Return canonical_path property for the object.
32    """
[1928]33    adapter = queryAdapter(obj, interface=ICanonicalPath)
34    if adapter:
35        return adapter.canonical_path
[782]36    return None
[1928]37
[3145]38
[1928]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
[2018]47
[3145]48#for compatibility with older plone versions
[2018]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.