1 # |
|
2 # Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 from pyams_content.features.search import ISearchFolder |
|
16 from pyams_content.shared.site import ISiteElementNavigation |
|
17 from pyams_content.shared.site.interfaces import IContentSummaryInfo |
|
18 from pyams_i18n.interfaces import II18n |
|
19 from pyams_skin.layer import IPyAMSUserLayer |
|
20 from pyams_utils.adapter import ContextRequestAdapter, adapter_config |
|
21 from pyams_utils.interfaces.url import IRelativeURL |
|
22 from pyams_utils.url import absolute_url |
|
23 from pyams_workflow.interfaces import IWorkflowPublicationInfo |
|
24 |
|
25 from pyams_content import _ |
|
26 |
|
27 |
|
28 @adapter_config(context=(ISearchFolder, IPyAMSUserLayer), provides=IRelativeURL) |
|
29 class SearchFolderRelativeUrlAdapter(ContextRequestAdapter): |
|
30 """Search folder relative URL adapter""" |
|
31 |
|
32 def get_url(self, display_context=None, view_name=None, query=None): |
|
33 return absolute_url(self.context, self.request, view_name, query) |
|
34 |
|
35 |
|
36 @adapter_config(context=(ISearchFolder, IPyAMSUserLayer), provides=ISiteElementNavigation) |
|
37 class SearchFolderNavigationAdapter(ContextRequestAdapter): |
|
38 """Search folder navigation adapter""" |
|
39 |
|
40 @property |
|
41 def visible(self): |
|
42 if not self.context.visible_in_list: |
|
43 return False |
|
44 return IWorkflowPublicationInfo(self.context).is_visible(self.request) |
|
45 |
|
46 |
|
47 @adapter_config(context=(ISearchFolder, IPyAMSUserLayer), provides=IContentSummaryInfo) |
|
48 class SearchFolderSummaryAdapter(ContextRequestAdapter): |
|
49 """Search folder summary adapter""" |
|
50 |
|
51 @property |
|
52 def title(self): |
|
53 i18n = II18n(self.context) |
|
54 return i18n.query_attribute('navigation_title', request=self.request) or \ |
|
55 i18n.query_attribute('title', request=self.request) |
|
56 |
|
57 @property |
|
58 def header(self): |
|
59 try: |
|
60 return II18n(self.context).query_attribute('header', request=self.request) |
|
61 except AttributeError: |
|
62 return None |
|
63 |
|
64 button_title = _("Consult folder") |
|