Added links to key-numbers portlet (merge dev-dc)
authorThierry Florac <thierry.florac@onf.fr>
Thu, 21 Jun 2018 08:48:45 +0200
changeset 722 081fcbb96f5c
parent 716 efd21a96cd5d (current diff)
parent 721 58b5506b26cc (diff)
child 723 d4b00aa0a9e0
child 744 d07037e1874d
Added links to key-numbers portlet (merge dev-dc)
src/pyams_content/component/keynumber/portlet/__init__.py
src/pyams_content/component/keynumber/portlet/zmi/__init__.py
src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt
src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.mo
src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.po
src/pyams_content/locales/pyams_content.pot
--- a/buildout.cfg	Wed Jun 20 18:15:49 2018 +0200
+++ b/buildout.cfg	Thu Jun 21 08:48:45 2018 +0200
@@ -7,12 +7,6 @@
 show-picked-versions = true
 newest = false
 
-allow-hosts =
-    bitbucket.org
-    *.python.org
-    *.sourceforge.net
-    github.com
-
 versions = versions
 newest = false
 #allow-picked-versions = false
--- a/src/pyams_content/component/keynumber/portlet/__init__.py	Wed Jun 20 18:15:49 2018 +0200
+++ b/src/pyams_content/component/keynumber/portlet/__init__.py	Thu Jun 21 08:48:45 2018 +0200
@@ -15,12 +15,16 @@
 # import standard library
 
 # import interfaces
+from pyams_content.component.association.interfaces import ASSOCIATION_CONTAINER_KEY
 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_content.features.menu import Menu
 from pyams_portal.portlet import PortletSettings, portlet_config, Portlet
+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
@@ -30,8 +34,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 +50,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 18:15:49 2018 +0200
+++ b/src/pyams_content/component/keynumber/portlet/interfaces/__init__.py	Thu Jun 21 08:48:45 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 18:15:49 2018 +0200
+++ b/src/pyams_content/component/keynumber/portlet/zmi/__init__.py	Thu Jun 21 08:48:45 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.component.keynumber.portlet import KEYNUMBER_PORTLET_LINKS_NAME
 from pyams_content.component.keynumber.zmi import KeyNumbersView
+from pyams_content.features.menu.zmi import MenuLinksView, LinksTable
 from pyams_form.form import AJAXEditForm
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_portal.portlet import PortletPreviewer
@@ -36,12 +43,6 @@
 from pyams_content import _
 
 
-@adapter_config(context=(Interface, IPyAMSLayer, Interface, IKeyNumberPortletSettings), provides=IPortletPreviewer)
-@template_config(template='templates/keynumber-preview.pt', layer=IPyAMSLayer)
-class KeyNumberPortletPreview(PortletPreviewer):
-    """Key number portlet previewer"""
-
-
 @pagelet_config(name='properties.html', context=IKeyNumberPortletSettings, layer=IPyAMSLayer,
                 permission=VIEW_SYSTEM_PERMISSION)
 class KeyNumberPortletEditor(PortletSettingsEditor):
@@ -65,10 +66,61 @@
     """Key number portlet settings editor, JSON renderer"""
 
 
+#
+# Key numbers portlet numbers view
+#
+
 @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 = 10
+
+
+#
+# Key numbers portlet links view
+#
+
+class KeyNumberPortletLinksTable(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++{0}'.format(KEYNUMBER_PORTLET_LINKS_NAME),
+                context=(IKeyNumberPortletMenu, IPyAMSLayer),
+                provides=IMenuLinksView)
+class KeyNumberPortletLinksView(MenuLinksView):
+    """Key numbers portlet links view"""
+
+    title = _("Associated links")
+    weight = 20
+
+    table_class = KeyNumberPortletLinksTable
+
+
+#
+# Key numbers portlet previewer
+#
+
+@adapter_config(context=(Interface, IPyAMSLayer, Interface, IKeyNumberPortletSettings), provides=IPortletPreviewer)
+@template_config(template='templates/keynumber-preview.pt', layer=IPyAMSLayer)
+class KeyNumberPortletPreviewer(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()
--- a/src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt	Wed Jun 20 18:15:49 2018 +0200
+++ b/src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt	Thu Jun 21 08:48:45 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">
+		<u><i18n:var translate="" >Associated links</i18n:var> :</u>
+		<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>
Binary file src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.mo has changed
--- a/src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.po	Wed Jun 20 18:15:49 2018 +0200
+++ b/src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.po	Thu Jun 21 08:48:45 2018 +0200
@@ -5,7 +5,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE 1.0\n"
-"POT-Creation-Date: 2018-06-20 17:59+0200\n"
+"POT-Creation-Date: 2018-06-21 08:26+0200\n"
 "PO-Revision-Date: 2015-09-10 10:42+0200\n"
 "Last-Translator: Thierry Florac <tflorac@ulthar.net>\n"
 "Language-Team: French\n"
@@ -275,7 +275,7 @@
 msgstr "Si 'non', ce média ne sera pas présenté aux internautes"
 
 #: src/pyams_content/component/gallery/interfaces/__init__.py:94
-#: src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:30
+#: src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:31
 #: src/pyams_content/component/paragraph/zmi/milestone.py:231
 #: src/pyams_content/component/paragraph/zmi/container.py:223
 #: src/pyams_content/component/paragraph/interfaces/milestone.py:45
@@ -478,7 +478,7 @@
 
 #: src/pyams_content/component/keynumber/__init__.py:180
 #: src/pyams_content/component/keynumber/zmi/__init__.py:198
-#: src/pyams_content/component/keynumber/portlet/zmi/__init__.py:74
+#: src/pyams_content/component/keynumber/portlet/zmi/__init__.py:79
 #: src/pyams_content/component/paragraph/interfaces/keynumber.py:29
 msgid "Key numbers"
 msgstr "Chiffres-clés"
@@ -523,19 +523,30 @@
 msgid "Key number was correctly added"
 msgstr "Le chiffre-clé a été ajouté."
 
-#: src/pyams_content/component/keynumber/portlet/__init__.py:52
+#: src/pyams_content/component/keynumber/portlet/__init__.py:71
 msgid "Key Numbers"
 msgstr "Chiffres-clés"
 
-#: src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:31
+#: src/pyams_content/component/keynumber/portlet/zmi/__init__.py:102
+#: src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt:22
+msgid "Associated links"
+msgstr "Liens associés"
+
+#: src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt:27
+#: src/pyams_content/features/menu/portlet/navigation/zmi/templates/double-preview.pt:12
+#: src/pyams_content/features/menu/portlet/navigation/zmi/templates/simple-preview.pt:9
+msgid "Link target is not published!"
+msgstr "Le contenu ciblé n'est pas publié"
+
+#: src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:32
 msgid "Portlet title"
 msgstr "Titre"
 
-#: src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:34
+#: src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:35
 msgid "Teaser"
 msgstr "Accroche"
 
-#: src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:35
+#: src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:36
 msgid "Short text displayed above key numbers"
 msgstr "Texte d'introduction des chiffres-clés"
 
@@ -4757,11 +4768,6 @@
 msgid "Navigation menus"
 msgstr "Menus de navigation"
 
-#: src/pyams_content/features/menu/portlet/navigation/zmi/templates/double-preview.pt:12
-#: src/pyams_content/features/menu/portlet/navigation/zmi/templates/simple-preview.pt:9
-msgid "Link target is not published!"
-msgstr "Le contenu ciblé n'est pas publié"
-
 #: src/pyams_content/features/menu/portlet/navigation/zmi/templates/simple-preview.pt:13
 msgid "Link has no illustration"
 msgstr "Le lien n'a pas d'illustration"
@@ -5049,6 +5055,9 @@
 msgid "Hidden header"
 msgstr "Ne pas afficher d'en-tête de pages"
 
+#~ msgid "Links"
+#~ msgstr "Liens"
+
 #~ msgid "View result items"
 #~ msgstr "Contenus extraits par la vue"
 
@@ -5282,9 +5291,6 @@
 #~ msgid "Image title"
 #~ msgstr "Légende de l'image"
 
-#~ msgid "Links"
-#~ msgstr "Liens"
-
 #~ msgid "Paragraph title"
 #~ msgstr "Titre du paragraphe"
 
--- a/src/pyams_content/locales/pyams_content.pot	Wed Jun 20 18:15:49 2018 +0200
+++ b/src/pyams_content/locales/pyams_content.pot	Thu Jun 21 08:48:45 2018 +0200
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE 1.0\n"
-"POT-Creation-Date: 2018-06-20 17:59+0200\n"
+"POT-Creation-Date: 2018-06-21 08:26+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -265,7 +265,7 @@
 msgstr ""
 
 #: ./src/pyams_content/component/gallery/interfaces/__init__.py:94
-#: ./src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:30
+#: ./src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:31
 #: ./src/pyams_content/component/paragraph/zmi/milestone.py:231
 #: ./src/pyams_content/component/paragraph/zmi/container.py:223
 #: ./src/pyams_content/component/paragraph/interfaces/milestone.py:45
@@ -458,7 +458,7 @@
 
 #: ./src/pyams_content/component/keynumber/__init__.py:180
 #: ./src/pyams_content/component/keynumber/zmi/__init__.py:198
-#: ./src/pyams_content/component/keynumber/portlet/zmi/__init__.py:74
+#: ./src/pyams_content/component/keynumber/portlet/zmi/__init__.py:79
 #: ./src/pyams_content/component/paragraph/interfaces/keynumber.py:29
 msgid "Key numbers"
 msgstr ""
@@ -503,19 +503,30 @@
 msgid "Key number was correctly added"
 msgstr ""
 
-#: ./src/pyams_content/component/keynumber/portlet/__init__.py:52
+#: ./src/pyams_content/component/keynumber/portlet/__init__.py:71
 msgid "Key Numbers"
 msgstr ""
 
-#: ./src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:31
+#: ./src/pyams_content/component/keynumber/portlet/zmi/__init__.py:102
+#: ./src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt:22
+msgid "Associated links"
+msgstr ""
+
+#: ./src/pyams_content/component/keynumber/portlet/zmi/templates/keynumber-preview.pt:27
+#: ./src/pyams_content/features/menu/portlet/navigation/zmi/templates/double-preview.pt:12
+#: ./src/pyams_content/features/menu/portlet/navigation/zmi/templates/simple-preview.pt:9
+msgid "Link target is not published!"
+msgstr ""
+
+#: ./src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:32
 msgid "Portlet title"
 msgstr ""
 
-#: ./src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:34
-msgid "Teaser"
-msgstr ""
-
 #: ./src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:35
+msgid "Teaser"
+msgstr ""
+
+#: ./src/pyams_content/component/keynumber/portlet/interfaces/__init__.py:36
 msgid "Short text displayed above key numbers"
 msgstr ""
 
@@ -4507,11 +4518,6 @@
 msgid "Navigation menus"
 msgstr ""
 
-#: ./src/pyams_content/features/menu/portlet/navigation/zmi/templates/double-preview.pt:12
-#: ./src/pyams_content/features/menu/portlet/navigation/zmi/templates/simple-preview.pt:9
-msgid "Link target is not published!"
-msgstr ""
-
 #: ./src/pyams_content/features/menu/portlet/navigation/zmi/templates/simple-preview.pt:13
 msgid "Link has no illustration"
 msgstr ""