[1685] | 1 | from zope.interface import Interface |
---|
[782] | 2 | from zope.component import queryAdapter |
---|
| 3 | |
---|
[3145] | 4 | #for compatibility with older plone versions |
---|
[2018] | 5 | try: |
---|
[3145] | 6 | from plone.indexer.decorator import indexer |
---|
[3146] | 7 | indexer |
---|
[2018] | 8 | IS_NEW = True |
---|
| 9 | except: |
---|
| 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] | 25 | from interfaces import ICanonicalPath |
---|
[1928] | 26 | from interfaces import ICanonicalLink |
---|
[782] | 27 | |
---|
[3145] | 28 | |
---|
[1685] | 29 | @indexer(Interface) |
---|
| 30 | def 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) |
---|
| 40 | def 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] | 49 | if not IS_NEW: |
---|
| 50 | from Products.CMFPlone.CatalogTool import registerIndexableAttribute |
---|
| 51 | map(registerIndexableAttribute, ('canonical_path', 'canonical_link'), |
---|
| 52 | (canonical_path, canonical_link)) |
---|