Added default keynumber portlet renderer dev-dc
authorDamien Correia
Tue, 10 Jul 2018 12:20:13 +0200
branchdev-dc
changeset 82 29e43fc3a6a0
parent 81 170cf23172b4
child 83 90b84b6b8caf
child 103 c1cef6215051
Added default keynumber portlet renderer
src/pyams_default_theme/component/keynumber/portlet/__init__.py
--- a/src/pyams_default_theme/component/keynumber/portlet/__init__.py	Tue Jul 10 12:17:34 2018 +0200
+++ b/src/pyams_default_theme/component/keynumber/portlet/__init__.py	Tue Jul 10 12:20:13 2018 +0200
@@ -16,9 +16,12 @@
 # import standard library
 
 # import interfaces
+from pyams_content.component.association.interfaces import IAssociationInfo
 from pyams_content.component.keynumber.portlet.interfaces import IKeyNumberPortletSettings
+from pyams_content.component.links import IInternalLink
 from pyams_portal.interfaces import IPortalContext, IPortletRenderer
 from pyams_skin.layer import IPyAMSLayer
+from pyams_workflow.interfaces import IWorkflowPublicationInfo
 
 # import packages
 from pyams_portal.portlet import PortletRenderer
@@ -29,10 +32,24 @@
 from pyams_default_theme import _
 
 
+class KeyNumberPortletDefaultRenderer(PortletRenderer):
+    """Key numbers portlet default renderer"""
+
+    def get_link_info(cls, link):
+        return IAssociationInfo(link)
+
+    @classmethod
+    def get_link_status(cls, link):
+        if not IInternalLink.providedBy(link):
+            return True
+        target = link.get_target()
+        return (target is not None) and IWorkflowPublicationInfo(target).is_published()
+
+
 @adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, IKeyNumberPortletSettings),
                 provides=IPortletRenderer)
 @template_config(template='templates/horizontal-render.pt', layer=IPyAMSLayer)
-class KeyNumberPortletHorizontalRenderer(PortletRenderer):
+class KeyNumberPortletHorizontalRenderer(KeyNumberPortletDefaultRenderer):
     """Key numbers portlet horizontal renderer"""
 
     label = _("Horizontal list with carousel")
@@ -41,7 +58,7 @@
 @adapter_config(name='vertical', context=(IPortalContext, IPyAMSLayer, Interface, IKeyNumberPortletSettings),
                 provides=IPortletRenderer)
 @template_config(template='templates/vertical-render.pt', layer=IPyAMSLayer)
-class KeyNumberPortletVerticalRenderer(PortletRenderer):
+class KeyNumberPortletVerticalRenderer(KeyNumberPortletDefaultRenderer):
     """Key numbers portlet vertical renderer"""
 
     label = _("Vertical list")