Updated reverse-links view to only display the last version containing a link to current context
--- a/src/pyams_content/shared/common/zmi/reverse.py Fri Jun 26 12:54:13 2020 +0200
+++ b/src/pyams_content/shared/common/zmi/reverse.py Mon Jun 29 18:23:29 2020 +0200
@@ -10,41 +10,37 @@
# FOR A PARTICULAR PURPOSE.
#
-__docformat__ = 'restructuredtext'
-
+from hypatia.catalog import CatalogQuery
+from hypatia.interfaces import ICatalog
+from hypatia.query import Any, Eq, Or
+from z3c.table.interfaces import IColumn, IValues
+from zope.interface import Interface, implementer
-# import standard library
-
-# import interfaces
-from hypatia.interfaces import ICatalog
+from pyams_catalog.query import CatalogResultSet
from pyams_content.shared.common.interfaces import IWfSharedContent
from pyams_content.shared.common.interfaces.zmi import ISiteRootDashboardTable
from pyams_content.shared.site.interfaces import ISiteContainer
+from pyams_pagelet.pagelet import pagelet_config
from pyams_portal.interfaces import IPortalTemplate
from pyams_sequence.interfaces import ISequentialIdInfo
+from pyams_skin.container import ContainerView
from pyams_skin.interfaces import IInnerPage
from pyams_skin.layer import IPyAMSLayer
-from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
-from pyams_workflow.interfaces import IWorkflowVersions
-from pyams_zmi.interfaces.menu import IContentManagementMenu
-from pyams_zmi.layer import IAdminLayer
-from z3c.table.interfaces import IValues, IColumn
-
-# import packages
-from hypatia.catalog import CatalogQuery
-from hypatia.query import Eq, Or, Any
-from pyams_catalog.query import CatalogResultSet
-from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.container import ContainerView
from pyams_skin.table import BaseTable, NameColumn
from pyams_skin.viewlet.menu import MenuItem
-from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
-from pyams_utils.list import unique_iter
+from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config
+from pyams_utils.interfaces import ICacheKeyValue, VIEW_SYSTEM_PERMISSION
+from pyams_utils.list import unique_iter_max
from pyams_utils.registry import get_utility
from pyams_utils.traversing import get_parent
from pyams_viewlet.viewlet import viewlet_config
+from pyams_workflow.interfaces import IWorkflowState
+from pyams_zmi.interfaces.menu import IContentManagementMenu
+from pyams_zmi.layer import IAdminLayer
from pyams_zmi.view import AdminView
-from zope.interface import implementer, Interface
+
+
+__docformat__ = 'restructuredtext'
from pyams_content import _
@@ -83,7 +79,7 @@
def get_item(result):
parent = get_parent(result, IWfSharedContent)
if parent is not None:
- return IWorkflowVersions(parent).get_last_versions(count=1)[0]
+ return parent
parent = get_parent(result, IPortalTemplate)
if parent is None:
parent = get_parent(result, ISiteContainer)
@@ -95,9 +91,12 @@
oid = ISequentialIdInfo(self.context).hex_oid
params = Or(Eq(catalog['link_reference'], oid),
Any(catalog['link_references'], {oid}))
- return unique_iter(map(get_item,
- CatalogResultSet(CatalogQuery(catalog).query(params,
- sort_index='modified_date'))))
+ return unique_iter_max(map(get_item,
+ CatalogResultSet(CatalogQuery(catalog).query(params))),
+ key=lambda x: getattr(ISequentialIdInfo(x, None),
+ 'oid', ICacheKeyValue(x)),
+ sort_key=lambda x: getattr(IWorkflowState(x, None),
+ 'version_id', ICacheKeyValue(x)))
@pagelet_config(name='reverse-links.html', context=IWfSharedContent, layer=IPyAMSLayer,