Added interface for addings menu label
authorThierry Florac <thierry.florac@onf.fr>
Mon, 20 Jun 2016 11:59:39 +0200
changeset 37 349fd1600cf9
parent 36 69a8e0ec5555
child 38 04c33c05f0be
Added interface for addings menu label
src/pyams_content/zmi/interfaces/__init__.py
src/pyams_content/zmi/viewlet/toplinks/__init__.py
--- a/src/pyams_content/zmi/interfaces/__init__.py	Thu Jun 02 15:32:09 2016 +0200
+++ b/src/pyams_content/zmi/interfaces/__init__.py	Mon Jun 20 11:59:39 2016 +0200
@@ -19,8 +19,13 @@
 from pyams_skin.interfaces.viewlet import IMenuItem
 
 # import packages
+from zope.interface import Interface, Attribute
 
 
+#
+# Custom menus interfaces
+#
+
 class IDashboardMenu(IMenuItem):
     """Dashboard menu"""
 
@@ -35,3 +40,13 @@
 
 class ISummaryMenu(IMenuItem):
     """Summary menu"""
+
+
+#
+# Custom ZMI interfaces
+#
+
+class IUserAddingsMenuLabel(Interface):
+    """Shared tool adding menu label"""
+
+    label = Attribute("Addings menu label")
--- a/src/pyams_content/zmi/viewlet/toplinks/__init__.py	Thu Jun 02 15:32:09 2016 +0200
+++ b/src/pyams_content/zmi/viewlet/toplinks/__init__.py	Mon Jun 20 11:59:39 2016 +0200
@@ -9,6 +9,7 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyams_content.zmi.interfaces import IUserAddingsMenuLabel
 
 __docformat__ = 'restructuredtext'
 
@@ -32,6 +33,7 @@
 from pyams_utils.registry import get_local_registry, get_utility
 from pyams_utils.url import absolute_url
 from pyams_viewlet.viewlet import viewlet_config
+from pyramid.threadlocal import get_current_registry
 
 from pyams_content import _
 
@@ -49,7 +51,7 @@
         registry = get_local_registry()
         for name, tool in registry.getUtilitiesFor(ISharedTool):
             menu = TopLinksMenu(self.context, self.request, self.__parent__, self)
-            menu.label = II18n(tool).query_attribute('short_name', request=self.request) or tool.__name__
+            menu.label = II18n(tool).query_attribute('title', request=self.request) or tool.__name__
             menu.url = absolute_url(tool, self.request, 'admin.html#dashboard.html')
             self.viewlets.append(menu)
 
@@ -89,12 +91,17 @@
     def update(self):
         super(UserAddingsMenu, self).update()
         catalog = get_utility(ICatalog)
+        registry = get_current_registry()
         params = And(Any(catalog['role:contributor'], {self.request.principal.id}),
                      NotEq(catalog['content_type'], None))
         for tool in sorted(unique(CatalogResultSet(CatalogQuery(catalog).query(params))),
                            key=lambda x: II18n(x).query_attribute('title', request=self.request)):
             menu = TopLinksMenu(self.context, self.request, self.__parent__, self)
-            menu.label = self.request.localizer.translate(tool.shared_content_factory.content_class.content_name)
+            adapter = registry.queryMultiAdapter((tool, self.request), IUserAddingsMenuLabel)
+            if adapter is None:
+                menu.label = self.request.localizer.translate(tool.shared_content_factory.content_class.content_name)
+            else:
+                menu.label = adapter.label
             menu.url = absolute_url(tool, self.request, 'add-shared-content.html')
             menu.data = {'data-toggle': 'modal'}
             self.viewlets.append(menu)