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.shared.site.interfaces import IContentLink, IContentSummaryInfo |
|
16 from pyams_i18n.interfaces import II18n |
|
17 from pyams_skin.layer import IPyAMSUserLayer |
|
18 from pyams_utils.adapter import adapter_config, ContextRequestAdapter |
|
19 from pyams_utils.interfaces.url import IRelativeURL |
|
20 |
|
21 from pyams_content import _ |
|
22 |
|
23 |
|
24 @adapter_config(context=(IContentLink, IPyAMSUserLayer), provides=IRelativeURL) |
|
25 def content_link_relative_url(context, request): |
|
26 """Content link relative URL""" |
|
27 target = context.get_target() |
|
28 if target is not None: |
|
29 return request.registry.queryMultiAdapter((target, request), IRelativeURL) |
|
30 |
|
31 |
|
32 @adapter_config(context=(IContentLink, IPyAMSUserLayer), provides=IContentSummaryInfo) |
|
33 class ContentLinkSummaryAdapter(ContextRequestAdapter): |
|
34 """Content link summary adapter""" |
|
35 |
|
36 target_info = None |
|
37 |
|
38 def __init__(self, context, request): |
|
39 super(ContentLinkSummaryAdapter, self).__init__(context, request) |
|
40 target = self.target = self.context.target |
|
41 if target is not None: |
|
42 self.target_info = request.registry.queryMultiAdapter((target, request), IContentSummaryInfo) |
|
43 |
|
44 @property |
|
45 def title(self): |
|
46 title = II18n(self.context).query_attribute('navigation_title', request=self.request) |
|
47 if (title is None) and (self.target_info is not None): |
|
48 title = self.target_info.title |
|
49 return title |
|
50 |
|
51 @property |
|
52 def header(self): |
|
53 if self.target_info is not None: |
|
54 return self.target_info.header |
|
55 |
|
56 @property |
|
57 def button_title(self): |
|
58 if self.target_info is not None: |
|
59 return self.target_info.button_title |
|
60 else: |
|
61 return self.request.localizer.translate(_("Consult content")) |
|