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

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

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