[1685] | 1 | from zope.interface import Interface |
---|
[782] | 2 | from zope.component import queryAdapter |
---|
| 3 | |
---|
[2018] | 4 | #for compatibility with older plone versions |
---|
| 5 | try: |
---|
| 6 | from plone.indexer.decorator import indexer |
---|
| 7 | IS_NEW = True |
---|
| 8 | except: |
---|
| 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 | |
---|
[782] | 22 | from interfaces import ICanonicalPath |
---|
[1928] | 23 | from interfaces import ICanonicalLink |
---|
[782] | 24 | |
---|
[1685] | 25 | @indexer(Interface) |
---|
| 26 | def canonical_path(obj, **kwargs): |
---|
[782] | 27 | """Return canonical_path property for the object. |
---|
| 28 | """ |
---|
[1928] | 29 | adapter = queryAdapter(obj, interface=ICanonicalPath) |
---|
| 30 | if adapter: |
---|
| 31 | return adapter.canonical_path |
---|
[782] | 32 | return None |
---|
[1928] | 33 | |
---|
| 34 | @indexer(Interface) |
---|
| 35 | def 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 |
---|
[2018] | 42 | |
---|
| 43 | #for compatibility with older plone versions |
---|
| 44 | if not IS_NEW: |
---|
| 45 | from Products.CMFPlone.CatalogTool import registerIndexableAttribute |
---|
| 46 | map(registerIndexableAttribute, ('canonical_path', 'canonical_link'), |
---|
| 47 | (canonical_path, canonical_link)) |
---|