Added site's external links adapters
authorThierry Florac <thierry.florac@onf.fr>
Fri, 23 Nov 2018 15:25:34 +0100
changeset 247 72e28694c4cb
parent 246 fe829f9d5c0d
child 248 44d8c16d9617
Added site's external links adapters
src/pyams_default_theme/shared/site/link.py
--- a/src/pyams_default_theme/shared/site/link.py	Fri Nov 23 15:24:51 2018 +0100
+++ b/src/pyams_default_theme/shared/site/link.py	Fri Nov 23 15:25:34 2018 +0100
@@ -12,8 +12,9 @@
 
 __docformat__ = 'restructuredtext'
 
-from pyams_content.shared.site.interfaces import IContentLink
-from pyams_default_theme.interfaces import IContentSummaryInfo
+from pyams_content.component.illustration import ILinkIllustration
+from pyams_content.shared.site.interfaces import IContentLink, IExternalContentLink
+from pyams_default_theme.interfaces import IContentNavigationIllustration, IContentSummaryInfo
 from pyams_i18n.interfaces import II18n
 from pyams_skin.layer import IPyAMSUserLayer
 from pyams_utils.adapter import ContextRequestAdapter, adapter_config
@@ -22,6 +23,10 @@
 from pyams_default_theme import _
 
 
+#
+# Content link adapters
+#
+
 @adapter_config(context=(IContentLink, IPyAMSUserLayer), provides=IRelativeURL)
 def content_link_relative_url(context, request):
     """Content link relative URL"""
@@ -64,3 +69,46 @@
         if not title:
             title = _("Consult content")
         return self.request.localizer.translate(title)
+
+
+@adapter_config(context=(IContentLink, IPyAMSUserLayer), provides=IContentNavigationIllustration)
+def content_link_illustration_factory(context, request):
+    """Content link illustration factory"""
+    target = context.target
+    if target is not None:
+        return request.registry.queryMultiAdapter((target, request), IContentNavigationIllustration)
+
+
+#
+# External content link adapters
+#
+
+@adapter_config(context=(IExternalContentLink, IPyAMSUserLayer), provides=IRelativeURL)
+class ExternalContentLinkRelativeUrl(ContextRequestAdapter):
+    """External content link relative URL"""
+
+    def get_url(self, display_context=None, view_name=None, query=None):
+        return self.context.url
+
+
+@adapter_config(context=(IExternalContentLink, IPyAMSUserLayer), provides=IContentSummaryInfo)
+class ExternalContentLinkSummaryAdapter(ContextRequestAdapter):
+    """External content link summary adapter"""
+
+    @property
+    def title(self):
+        return II18n(self.context).query_attribute('navigation_title', request=self.request)
+
+    @property
+    def header(self):
+        return II18n(self.context).query_attribute('navigation_header', request=self.request)
+
+    @property
+    def button_title(self):
+        return self.request.localizer.translate(_("Consult content"))
+
+
+@adapter_config(context=(IExternalContentLink, IPyAMSUserLayer), provides=IContentNavigationIllustration)
+def external_content_link_illustration_factory(context, request):
+    """External content link illustration factory"""
+    return request.registry.queryAdapter(context, ILinkIllustration)