Added interface and adapter for dashboard search header
authorThierry Florac <thierry.florac@onf.fr>
Wed, 15 Nov 2017 17:25:47 +0100
changeset 279 c31da1985a3b
parent 278 f78a3411bf62
child 280 a87f40e0f10c
Added interface and adapter for dashboard search header
src/pyams_content/shared/common/interfaces/zmi.py
src/pyams_content/shared/common/zmi/dashboard.py
src/pyams_content/shared/common/zmi/templates/dashboard.pt
src/pyams_content/shared/site/zmi/manager.py
--- a/src/pyams_content/shared/common/interfaces/zmi.py	Wed Nov 15 17:05:38 2017 +0100
+++ b/src/pyams_content/shared/common/interfaces/zmi.py	Wed Nov 15 17:25:47 2017 +0100
@@ -17,17 +17,21 @@
 
 # import interfaces
 from pyams_skin.interfaces.container import ITable
-from pyams_skin.layer import IPyAMSLayer
 
 # import packages
-from pyams_template.template import layout_config
-from zope.interface import Interface
+from zope.interface import Interface, Attribute
 
 
 class IDashboardTable(ITable):
     """Base dashboard table marker interface"""
 
 
+class IDashboardSearchHeader(Interface):
+    """Dashboard search header adapter"""
+
+    title = Attribute("Header title")
+
+
 class ISharedToolDashboardTable(IDashboardTable):
     """Shared tool dashboard table marker interface"""
 
--- a/src/pyams_content/shared/common/zmi/dashboard.py	Wed Nov 15 17:05:38 2017 +0100
+++ b/src/pyams_content/shared/common/zmi/dashboard.py	Wed Nov 15 17:25:47 2017 +0100
@@ -20,7 +20,8 @@
 from pyams_content.interfaces import MANAGE_SITE_ROOT_PERMISSION, PUBLISH_CONTENT_PERMISSION
 from pyams_content.profile.interfaces import IAdminProfile
 from pyams_content.shared.common.interfaces import IBaseSharedTool, IWfSharedContent, IManagerRestrictions
-from pyams_content.shared.common.interfaces.zmi import IDashboardTable, ISharedToolDashboardTable
+from pyams_content.shared.common.interfaces.zmi import IDashboardTable, ISharedToolDashboardTable, \
+    IDashboardSearchHeader
 from pyams_content.zmi.interfaces import IDashboardMenu, IMyDashboardMenu, IAllContentsMenu
 from pyams_i18n.interfaces import II18n
 from pyams_security.interfaces import ISecurityManager
@@ -284,6 +285,18 @@
         super(SharedToolDashboardView, self).update()
         [table.update() for table in self.tables]
 
+    @property
+    def header_title(self):
+        registry = self.request.registry
+        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 &laquo;&nbsp;{type}&nbsp;&raquo;")).format(
+                type=II18n(self.context).query_attribute('title', request=self.request)
+            )
+
 
 @adapter_config(context=(IBaseSharedTool, IPyAMSLayer, SharedToolDashboardView), provides=IPageHeader)
 class SharedToolDashboardHeaderAdapter(DefaultPageHeaderAdapter):
--- a/src/pyams_content/shared/common/zmi/templates/dashboard.pt	Wed Nov 15 17:05:38 2017 +0100
+++ b/src/pyams_content/shared/common/zmi/templates/dashboard.pt	Wed Nov 15 17:25:47 2017 +0100
@@ -15,8 +15,7 @@
 	<div class="widget-body">
 		<div class="ams-widget">
 			<header>
-				<h2 i18n:translate="">SEARCH - Between all contents of type &laquo;&nbsp;<span i18n:name="type"
-					tal:content="i18n:context.title">type</span>&nbsp;&raquo;</h2>
+				<h2 tal:content="structure view.header_title">SEARCH - Between all contents of type</h2>
 			</header>
 			<div class="padding-10 padding-bottom-0">
 				<form class="ams-form clearfix margin-bottom-10" method="post" action="quick-search.html"
--- a/src/pyams_content/shared/site/zmi/manager.py	Wed Nov 15 17:05:38 2017 +0100
+++ b/src/pyams_content/shared/site/zmi/manager.py	Wed Nov 15 17:25:47 2017 +0100
@@ -9,6 +9,8 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyams_content.shared.common.interfaces.zmi import IDashboardSearchHeader
+from pyams_content.shared.common.zmi.dashboard import SharedToolDashboardView
 
 __docformat__ = 'restructuredtext'
 
@@ -34,7 +36,7 @@
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.table import DefaultElementEditorAdapter
 from pyams_skin.viewlet.toolbar import ToolbarMenuItem
-from pyams_utils.adapter import adapter_config, ContextRequestAdapter
+from pyams_utils.adapter import adapter_config, ContextRequestAdapter, ContextRequestViewAdapter
 from pyams_utils.registry import query_utility
 from pyams_utils.unicode import translate_string
 from pyams_utils.url import absolute_url
@@ -125,3 +127,15 @@
 
     view_name = 'admin'
     modal_target = False
+
+
+@adapter_config(context=(ISiteManager, IAdminLayer, SharedToolDashboardView), provides=IDashboardSearchHeader)
+class SiteManagerDashboardSearchHeaderAdapter(ContextRequestViewAdapter):
+    """Site manager dashboard search header adapter"""
+
+    @property
+    def title(self):
+        translate = self.request.localizer.translate
+        return translate(_("SEARCH - Between all contents published into &laquo;&nbsp;{site}&nbsp;&raquo;")).format(
+            site=II18n(self.context).query_attribute('title', request=self.request)
+        )