1 | from zope.interface import Interface |
---|
2 | from zope.component import queryAdapter |
---|
3 | |
---|
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 | |
---|
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 | |
---|
24 | from interfaces import ICanonicalPath |
---|
25 | from interfaces import ICanonicalLink |
---|
26 | |
---|
27 | |
---|
28 | @indexer(Interface) |
---|
29 | def 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) |
---|
39 | def 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 |
---|
48 | if not IS_NEW: |
---|
49 | from Products.CMFPlone.CatalogTool import registerIndexableAttribute |
---|
50 | map(registerIndexableAttribute, ('canonical_path', 'canonical_link'), |
---|
51 | (canonical_path, canonical_link)) |
---|