--- a/src/pyams_content/component/keynumber/portlet/__init__.py Wed Jun 20 12:21:20 2018 +0200
+++ b/src/pyams_content/component/keynumber/portlet/__init__.py Wed Jun 20 15:57:55 2018 +0200
@@ -16,11 +16,15 @@
# import interfaces
from pyams_content.component.keynumber.interfaces import IKeyNumberContainerTarget, IKeyNumberContainer
-from pyams_content.component.keynumber.portlet.interfaces import IKeyNumberPortletSettings
+from pyams_content.component.keynumber.portlet.interfaces import IKeyNumberPortletSettings, IKeyNumberPortletMenu
+from pyams_content.features.menu.interfaces import IMenuLinksContainerTarget, IMenuLinksContainer
from pyams_utils.interfaces import VIEW_PERMISSION
# import packages
from pyams_portal.portlet import PortletSettings, portlet_config, Portlet
+from pyams_content.component.association.interfaces import ASSOCIATION_CONTAINER_KEY
+from pyams_content.features.menu import Menu
+from pyams_utils.adapter import get_annotation_adapter, adapter_config
from pyams_utils.factory import factory_config
from zope.interface import implementer
from zope.schema.fieldproperty import FieldProperty
@@ -29,9 +33,11 @@
KEYNUMBER_PORTLET_NAME = "pyams_portal.portlet.keynumber"
+KEYNUMBER_PORTLET_LINKS_NAME = 'links'
+KEYNUMBER_PORTLET_LINKS_KEY = '{0}::{1}'.format(ASSOCIATION_CONTAINER_KEY, KEYNUMBER_PORTLET_LINKS_NAME)
-@implementer(IKeyNumberPortletSettings, IKeyNumberContainerTarget)
+@implementer(IKeyNumberPortletSettings, IKeyNumberContainerTarget, IMenuLinksContainerTarget)
@factory_config(provided=IKeyNumberPortletSettings)
class KeyNumberPortletSettings(PortletSettings):
"""Key Number portlet settings"""
@@ -43,6 +49,18 @@
def keynumbers(self):
return IKeyNumberContainer(self)
+ @property
+ def links(self):
+ return get_annotation_adapter(self, KEYNUMBER_PORTLET_LINKS_KEY, Menu,
+ markers=IKeyNumberPortletMenu,
+ name='++ass++' + KEYNUMBER_PORTLET_LINKS_NAME)
+
+
+@adapter_config(name=KEYNUMBER_PORTLET_LINKS_NAME, context=IKeyNumberPortletSettings, provides=IMenuLinksContainer)
+def keynumber_links_adapter(context):
+ """Key number settings links factory"""
+ return context.links
+
@portlet_config(permission=VIEW_PERMISSION)
class KeyNumberPortlet(Portlet):
--- a/src/pyams_content/component/keynumber/portlet/interfaces/__init__.py Wed Jun 20 12:21:20 2018 +0200
+++ b/src/pyams_content/component/keynumber/portlet/interfaces/__init__.py Wed Jun 20 15:57:55 2018 +0200
@@ -20,6 +20,7 @@
# import packages
from pyams_i18n.schema import I18nTextLineField, I18nTextField
+from zope.interface import Attribute, Interface
from pyams_content import _
@@ -34,3 +35,9 @@
teaser = I18nTextField(title=_("Teaser"),
description=_("Short text displayed above key numbers"),
required=False)
+
+ links = Attribute("Navigation links")
+
+
+class IKeyNumberPortletMenu(Interface):
+ """Key numbers portlet menu marker interface"""
--- a/src/pyams_content/component/keynumber/portlet/zmi/__init__.py Wed Jun 20 12:21:20 2018 +0200
+++ b/src/pyams_content/component/keynumber/portlet/zmi/__init__.py Wed Jun 20 15:57:55 2018 +0200
@@ -10,21 +10,28 @@
# FOR A PARTICULAR PURPOSE.
#
+
__docformat__ = 'restructuredtext'
# import standard library
# import interfaces
-from pyams_content.component.keynumber.portlet.interfaces import IKeyNumberPortletSettings
+from pyams_content.component.association.interfaces import IAssociationInfo
+from pyams_content.component.keynumber.portlet.interfaces import IKeyNumberPortletSettings, IKeyNumberPortletMenu
+from pyams_content.features.menu.zmi import IMenuLinksView
+from pyams_content.component.links.interfaces import IInternalLink
from pyams_portal.interfaces import IPortletPreviewer
from pyams_form.interfaces.form import IInnerSubForm, IInnerTabForm
from pyams_pagelet.interfaces import IPagelet
from pyams_skin.layer import IPyAMSLayer
from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+from pyams_workflow.interfaces import IWorkflowPublicationInfo
# import packages
+from pyams_content.features.menu.zmi import MenuLinksView, LinksTable
from pyams_content.component.keynumber.zmi import KeyNumbersView
+from pyams_content.component.keynumber.portlet import KEYNUMBER_PORTLET_LINKS_NAME
from pyams_form.form import AJAXEditForm
from pyams_pagelet.pagelet import pagelet_config
from pyams_portal.portlet import PortletPreviewer
@@ -32,7 +39,6 @@
from pyams_template.template import template_config
from pyams_utils.adapter import adapter_config
from zope.interface import Interface
-
from pyams_content import _
@@ -41,6 +47,17 @@
class KeyNumberPortletPreview(PortletPreviewer):
"""Key number portlet previewer"""
+ @classmethod
+ 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()
+
@pagelet_config(name='properties.html', context=IKeyNumberPortletSettings, layer=IPyAMSLayer,
permission=VIEW_SYSTEM_PERMISSION)
@@ -68,7 +85,29 @@
@adapter_config(name='keynumber-portlet-numbers',
context=(IKeyNumberPortletSettings, IPyAMSLayer, PortletSettingsPropertiesEditor),
provides=IInnerSubForm)
-class PortletKeynumberLinksView(KeyNumbersView):
- """Portlet key numbers view"""
+class KeynumberPortletNumbersView(KeyNumbersView):
+ """Key number portlet numbers view"""
title = _("Key numbers")
+ weight = 20
+
+
+class KeyNumbersPortletLinksTable(LinksTable):
+ """Key Numbers links associations table"""
+
+ associations_name = KEYNUMBER_PORTLET_LINKS_NAME
+
+
+@adapter_config(name='keynumber-portlet-links',
+ context=(IKeyNumberPortletSettings, IPyAMSLayer, PortletSettingsPropertiesEditor),
+ provides=IInnerSubForm)
+@adapter_config(name='++ass++' + KEYNUMBER_PORTLET_LINKS_NAME,
+ context=(IKeyNumberPortletMenu, IPyAMSLayer),
+ provides=IMenuLinksView)
+class KeynumberPortletLinksView(MenuLinksView):
+ """Key numbers portlet links view"""
+
+ title = _("Links")
+ weight = 10
+
+ table_class = KeyNumbersPortletLinksTable
--- a/src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt Wed Jun 20 12:21:20 2018 +0200
+++ b/src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt Wed Jun 20 15:57:55 2018 +0200
@@ -17,4 +17,19 @@
<span tal:content="i18n:number.text">text</span>
</li>
</ul>
+ <div tal:define="visible_links list(settings.links.get_visible_items())"
+ tal:condition="visible_links">
+ - <span i18n:translate="" >Links</span>:
+ <ul>
+ <li tal:repeat="link visible_links">
+ <i class="fa fa-fw fa-eye-slash text-danger hint opaque align-base"
+ tal:condition="not:view.get_link_status(link)"
+ title="Link target is not published!" i18n:attributes="title"></i>
+ <tal:var define="info view.get_link_info(link)">
+ <span tal:content="info.user_title">User title</span>
+ <span tal:content="info.inner_title">Inner title</span>
+ </tal:var>
+ </li>
+ </ul>
+ </div>
</div>