diff -r 9479901b53a5 -r ed31bfceddda src/pyams_content/shared/common/zmi/dashboard.py --- a/src/pyams_content/shared/common/zmi/dashboard.py Wed Jul 01 14:10:50 2020 +0200 +++ b/src/pyams_content/shared/common/zmi/dashboard.py Wed Jul 01 18:05:38 2020 +0200 @@ -10,27 +10,25 @@ # FOR A PARTICULAR PURPOSE. # -__docformat__ = 'restructuredtext' - from hypatia.catalog import CatalogQuery from hypatia.interfaces import ICatalog -from hypatia.query import And, Or, Eq, Any +from hypatia.query import And, Any, Eq, Or from z3c.table.column import GetAttrColumn -from z3c.table.interfaces import IValues, IColumn +from z3c.table.interfaces import IColumn, IValues from zope.dublincore.interfaces import IZopeDublinCore -from zope.interface import implementer, Interface +from zope.interface import Interface, implementer from zope.intid.interfaces import IIntIds from pyams_catalog.query import CatalogResultSet from pyams_content.interfaces import MANAGE_SITE_ROOT_PERMISSION, PUBLISH_CONTENT_PERMISSION from pyams_content.profile.interfaces import IAdminProfile from pyams_content.shared.common import CONTENT_TYPES -from pyams_content.shared.common.interfaces import IBaseSharedTool, IWfSharedContent, IManagerRestrictions -from pyams_content.shared.common.interfaces.types import IWfTypedSharedContent -from pyams_content.shared.common.interfaces.zmi import IDashboardTable, ISharedToolDashboardTable, \ - IDashboardSearchHeader +from pyams_content.shared.common.interfaces import IBaseSharedTool, IManagerRestrictions, \ + ISharedTool, IWfSharedContent +from pyams_content.shared.common.interfaces.zmi import IDashboardSearchHeader, IDashboardTable, \ + IDashboardTypeColumnValue, ISharedToolDashboardTable from pyams_content.zmi import pyams_content -from pyams_content.zmi.interfaces import IDashboardMenu, IMyDashboardMenu, IAllContentsMenu +from pyams_content.zmi.interfaces import IAllContentsMenu, IDashboardMenu, IMyDashboardMenu from pyams_i18n.interfaces import II18n from pyams_pagelet.pagelet import pagelet_config from pyams_security.interfaces import ISecurityManager @@ -40,11 +38,11 @@ from pyams_skin.interfaces.container import ITableElementName from pyams_skin.layer import IPyAMSLayer from pyams_skin.page import DefaultPageHeaderAdapter -from pyams_skin.table import BaseTable, I18nColumn, NameColumn, JsActionColumn +from pyams_skin.table import BaseTable, I18nColumn, JsActionColumn, NameColumn from pyams_skin.viewlet.menu import MenuItem from pyams_template.template import template_config -from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter -from pyams_utils.date import format_datetime, SH_DATETIME_FORMAT +from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config +from pyams_utils.date import SH_DATETIME_FORMAT, format_datetime from pyams_utils.fanstatic import get_resource_path from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION from pyams_utils.list import unique_iter @@ -54,11 +52,15 @@ from pyams_utils.traversing import get_parent from pyams_viewlet.manager import viewletmanager_config from pyams_viewlet.viewlet import viewlet_config -from pyams_workflow.interfaces import IWorkflowState, IWorkflow, IWorkflowVersions, IWorkflowPublicationInfo +from pyams_workflow.interfaces import IWorkflow, IWorkflowPublicationInfo, IWorkflowState, \ + IWorkflowVersions from pyams_zmi.interfaces.menu import IContentManagementMenu from pyams_zmi.layer import IAdminLayer from pyams_zmi.view import InnerAdminView + +__docformat__ = 'restructuredtext' + from pyams_content import _ @@ -102,17 +104,21 @@ class SharedToolDashboardTypeColumn(I18nColumn, GetAttrColumn): """Shared tool dashboard type column""" - _header = _("Type") + _header = _("Content type") weight = 9 def getValue(self, obj): - content = IWfTypedSharedContent(obj, None) - if content is not None: - data_type = content.get_data_type() - if data_type is not None: - return II18n(data_type).query_attribute('navigation_label', request=self.request) or \ - II18n(data_type).query_attribute('label', request=self.request) - return '--' + value = self.request.registry.queryMultiAdapter((obj, self.request, self.table), + IDashboardTypeColumnValue) + return value or '--' + + +@adapter_config(name='type', context=(ISharedTool, IPyAMSLayer, ISharedToolDashboardTable), + provides=IColumn) +class SharedContentDashboardTypeColumn(SharedToolDashboardTypeColumn): + """Shared tool dashboard type column""" + + _header = _("Type") @adapter_config(name='name', context=(Interface, IPyAMSLayer, IDashboardTable), provides=IColumn) @@ -122,7 +128,8 @@ _header = _("Title") -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, IDashboardTable), provides=ITableElementName) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, IDashboardTable), + provides=ITableElementName) class SharedToolDashboardNameAdapter(ContextRequestViewAdapter): """Shared tool dashboard name adapter""" @@ -131,7 +138,8 @@ return II18n(self.context).query_attribute('title', request=self.request) -@adapter_config(context=(IWfSharedContent, IPyAMSLayer, IDashboardTable), provides=ITableElementName) +@adapter_config(context=(IWfSharedContent, IPyAMSLayer, IDashboardTable), + provides=ITableElementName) class SharedToolDashboardContentNameAdapter(ContextRequestViewAdapter): """Shared tool dashboard content name adapter""" @@ -140,7 +148,8 @@ return II18n(self.context).query_attribute('title', request=self.request) -@adapter_config(name='sequence', context=(Interface, IPyAMSLayer, IDashboardTable), provides=IColumn) +@adapter_config(name='sequence', context=(Interface, IPyAMSLayer, IDashboardTable), + provides=IColumn) class SharedToolDashboardSequenceColumn(I18nColumn, GetAttrColumn): """Shared tool dashboard sequence ID column""" @@ -160,7 +169,8 @@ return '--' -@adapter_config(name='status', context=(Interface, IPyAMSLayer, IDashboardTable), provides=IColumn) +@adapter_config(name='status', context=(Interface, IPyAMSLayer, IDashboardTable), + provides=IColumn) class SharedToolDashboardStatusColumn(I18nColumn, GetAttrColumn): """Shared tool dashboard status column""" @@ -187,7 +197,8 @@ return '--' -@adapter_config(name='status_date', context=(Interface, IPyAMSLayer, IDashboardTable), provides=IColumn) +@adapter_config(name='status_date', context=(Interface, IPyAMSLayer, IDashboardTable), + provides=IColumn) class SharedToolDashboardStatusDateColumn(I18nColumn, GetAttrColumn): """Shared tool dashboard status date column""" @@ -204,7 +215,8 @@ return '--' -@adapter_config(name='version', context=(Interface, IPyAMSLayer, IDashboardTable), provides=IColumn) +@adapter_config(name='version', context=(Interface, IPyAMSLayer, IDashboardTable), + provides=IColumn) class SharedToolDashboardVersionColumn(I18nColumn, GetAttrColumn): """Shared tool dashboard version column""" @@ -219,7 +231,8 @@ return '--' -@adapter_config(name='status_principal', context=(Interface, IPyAMSLayer, IDashboardTable), provides=IColumn) +@adapter_config(name='status_principal', context=(Interface, IPyAMSLayer, IDashboardTable), + provides=IColumn) class SharedToolDashboardStatusPrincipalColumn(I18nColumn, GetAttrColumn): """Shared tool dashboard status principal column""" @@ -237,7 +250,8 @@ return '--' -@adapter_config(name='owner', context=(Interface, IPyAMSLayer, IDashboardTable), provides=IColumn) +@adapter_config(name='owner', context=(Interface, IPyAMSLayer, IDashboardTable), + provides=IColumn) class SharedToolDashboardOwnerColumn(I18nColumn, GetAttrColumn): """Shared tool dashboard owner column""" @@ -259,7 +273,8 @@ return '--' -@adapter_config(name='modified', context=(Interface, IPyAMSLayer, IDashboardTable), provides=IColumn) +@adapter_config(name='modified', context=(Interface, IPyAMSLayer, IDashboardTable), + provides=IColumn) class SharedToolDashboardModifiedColumn(I18nColumn, GetAttrColumn): """Shared tool dashboard modified column""" @@ -291,7 +306,8 @@ url = '#dashboard.html' -@pagelet_config(name='dashboard.html', context=IBaseSharedTool, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) +@pagelet_config(name='dashboard.html', context=IBaseSharedTool, layer=IPyAMSLayer, + permission=VIEW_SYSTEM_PERMISSION) @template_config(template='templates/dashboard.pt', layer=IAdminLayer) class SharedToolDashboardView(InnerAdminView): """Shared tool dashboard view""" @@ -314,17 +330,20 @@ @property def header_title(self): registry = self.request.registry - adapter = registry.queryMultiAdapter((self.context, self.request, self), IDashboardSearchHeader) + adapter = registry.queryMultiAdapter((self.context, self.request, self), + IDashboardSearchHeader) if adapter is not None: return adapter.title else: translate = self.request.localizer.translate - return translate(_("SEARCH - Between all contents of type « {type} »")).format( + return translate(_("SEARCH - Between all contents of type " + "« {type} »")).format( type=II18n(self.context).query_attribute('title', request=self.request) ) -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolDashboardView), provides=IPageHeader) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolDashboardView), + provides=IPageHeader) class SharedToolDashboardHeaderAdapter(DefaultPageHeaderAdapter): """Shared tool properties header adapter""" @@ -346,7 +365,8 @@ _plural_title = _("MANAGER - {0} contents waiting for your action") -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolDashboardManagerWaitingTable), provides=IValues) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolDashboardManagerWaitingTable), + provides=IValues) class SharedToolDashboardManagerWaitingValues(ContextRequestViewAdapter): """Shared tool dashboard waiting values adapter""" @@ -359,8 +379,9 @@ Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ Any(catalog['workflow_state'], workflow.waiting_states) yield from filter(self.check_access, - unique_iter(map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), - key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], + unique_iter(map(lambda x: sorted( + IWorkflowVersions(x).get_versions(IWorkflowState(x).state), + key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], CatalogResultSet(CatalogQuery(catalog).query(params, sort_index='modified_date'))))) @@ -390,7 +411,8 @@ dt_sort_order = 'asc' -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolDashboardOwnerWaitingTable), provides=IValues) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolDashboardOwnerWaitingTable), + provides=IValues) class SharedToolDashboardOwnerWaitingValues(ContextRequestViewAdapter): """Shared tool dashboard waiting owned contents values adapter""" @@ -403,10 +425,11 @@ Any(catalog['content_type'], CONTENT_TYPES.keys()) & \ Any(catalog['workflow_state'], workflow.waiting_states) & \ Eq(catalog['workflow_principal'], self.request.principal.id) - yield from unique_iter(map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), - key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], - CatalogResultSet(CatalogQuery(catalog).query(params, - sort_index='modified_date')))) + yield from unique_iter( + map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), + key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], + CatalogResultSet(CatalogQuery(catalog).query(params, + sort_index='modified_date')))) # @@ -427,7 +450,8 @@ return _("CONTRIBUTOR - Last {0} modified contents") -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolDashboardOwnerModifiedTable), provides=IValues) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolDashboardOwnerModifiedTable), + provides=IValues) class SharedToolDashboardOwnerModifiedValues(ContextRequestViewAdapter): """Shared tool dashboard waiting owned contents values adapter""" @@ -439,12 +463,13 @@ Any(catalog['content_type'], CONTENT_TYPES.keys()), Or(Eq(catalog['role:owner'], self.request.principal.id), Eq(catalog['role:contributor'], self.request.principal.id))) - yield from unique_iter(map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), - key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], - CatalogResultSet(CatalogQuery(catalog).query(params, - limit=50, - sort_index='modified_date', - reverse=True)))) + yield from unique_iter( + map(lambda x: sorted(IWorkflowVersions(x).get_versions(IWorkflowState(x).state), + key=lambda y: IZopeDublinCore(y).modified, reverse=True)[0], + CatalogResultSet(CatalogQuery(catalog).query(params, + limit=50, + sort_index='modified_date', + reverse=True)))) # @@ -540,14 +565,16 @@ reverse=True)))) -@pagelet_config(name='my-favorites.html', context=IBaseSharedTool, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION) +@pagelet_config(name='my-favorites.html', context=IBaseSharedTool, layer=IPyAMSLayer, + permission=VIEW_SYSTEM_PERMISSION) class SharedToolFavoritesView(InnerAdminView, ContainerView): """Shared tool favorites view""" table_class = SharedToolFavoritesTable -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolFavoritesView), provides=IPageHeader) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolFavoritesView), + provides=IPageHeader) class SharedToolFavoritesHeaderAdapter(DefaultPageHeaderAdapter): """Shared tool favorites header adapter""" @@ -584,7 +611,8 @@ _plural_title = _("CONTRIBUTOR - {0} contents in preparation") -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolPreparationsTable), provides=IValues) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolPreparationsTable), + provides=IValues) class SharedToolPreparationsValues(ContextRequestViewAdapter): """Shared tool preparations values adapter""" @@ -611,7 +639,8 @@ table_class = SharedToolPreparationsTable -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolPreparationsView), provides=IPageHeader) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolPreparationsView), + provides=IPageHeader) class SharedToolPreparationsHeaderAdapter(DefaultPageHeaderAdapter): """Shared tool preparations header adapter""" @@ -648,7 +677,8 @@ _plural_title = _("CONTRIBUTOR - {0} submitted contents") -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolSubmissionsTable), provides=IValues) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolSubmissionsTable), + provides=IValues) class SharedToolSubmissionsValues(ContextRequestViewAdapter): """Shared tool submissions values adapter""" @@ -675,7 +705,8 @@ table_class = SharedToolSubmissionsTable -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolSubmissionsView), provides=IPageHeader) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolSubmissionsView), + provides=IPageHeader) class SharedToolSubmissionsHeaderAdapter(DefaultPageHeaderAdapter): """Shared tool submissions header adapter""" @@ -712,7 +743,8 @@ _plural_title = _("CONTRIBUTOR - {0} published contents") -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolPublicationsTable), provides=IValues) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolPublicationsTable), + provides=IValues) class SharedToolPublicationsValues(ContextRequestViewAdapter): """Shared tool publications values adapter""" @@ -739,7 +771,8 @@ table_class = SharedToolPublicationsTable -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolPublicationsView), provides=IPageHeader) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolPublicationsView), + provides=IPageHeader) class SharedToolPublicationsHeaderAdapter(DefaultPageHeaderAdapter): """Shared tool publications header adapter""" @@ -776,7 +809,8 @@ _plural_title = _("CONTRIBUTOR - {0} retired contents") -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolRetiredContentsTable), provides=IValues) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolRetiredContentsTable), + provides=IValues) class SharedToolRetiredContentsValues(ContextRequestViewAdapter): """Shared tool retired contents values adapter""" @@ -803,7 +837,8 @@ table_class = SharedToolRetiredContentsTable -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolRetiredContentsView), provides=IPageHeader) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolRetiredContentsView), + provides=IPageHeader) class SharedToolRetiredContentsHeaderAdapter(DefaultPageHeaderAdapter): """Shared tool retired contents header adapter""" @@ -840,7 +875,8 @@ _plural_title = _("CONTRIBUTOR - {0} archived contents") -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolArchivedContentsTable), provides=IValues) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolArchivedContentsTable), + provides=IValues) class SharedToolArchivedContentsValues(ContextRequestViewAdapter): """Shared tool archived contents values adapter""" @@ -873,7 +909,8 @@ table_class = SharedToolArchivedContentsTable -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolArchivedContentsView), provides=IPageHeader) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolArchivedContentsView), + provides=IPageHeader) class SharedToolArchivedContentsHeaderAdapter(DefaultPageHeaderAdapter): """Shared tool archived contents header adapter""" @@ -932,7 +969,8 @@ return _("CONTRIBUTORS - Last published contents (in the limit of 50)") -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolAllPublicationsTable), provides=IValues) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolAllPublicationsTable), + provides=IValues) class SharedToolAllPublicationsValues(ContextRequestViewAdapter): """Shared tool published contents values adapter""" @@ -958,7 +996,8 @@ table_class = SharedToolAllPublicationsTable -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolAllPublicationsView), provides=IPageHeader) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolAllPublicationsView), + provides=IPageHeader) class SharedToolAllPublicationsHeaderAdapter(DefaultPageHeaderAdapter): """Shared tool published contents header adapter""" @@ -1001,7 +1040,8 @@ return _("CONTRIBUTORS - Last updated contents (in the limit of 50)") -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolAllUpdatesTable), provides=IValues) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolAllUpdatesTable), + provides=IValues) class SharedToolAllUpdatesValues(ContextRequestViewAdapter): """Shared tool updated contents values adapter""" @@ -1025,7 +1065,8 @@ table_class = SharedToolAllUpdatesTable -@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolAllUpdatesView), provides=IPageHeader) +@adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolAllUpdatesView), + provides=IPageHeader) class SharedToolAllUpdatesHeaderAdapter(DefaultPageHeaderAdapter): """Shared tool updated contents header adapter"""