Added check to filter tools not implementing ISharedTool (like SiteManager)
authorThierry Florac <tflorac@ulthar.net>
Wed, 06 Nov 2019 16:04:24 +0100
changeset 1381 db5205cef064
parent 1380 2bb74b846776
child 1382 eb952f44298e
Added check to filter tools not implementing ISharedTool (like SiteManager)
src/pyams_content/zmi/viewlet/toplinks/__init__.py
--- a/src/pyams_content/zmi/viewlet/toplinks/__init__.py	Fri Oct 18 16:58:24 2019 +0200
+++ b/src/pyams_content/zmi/viewlet/toplinks/__init__.py	Wed Nov 06 16:04:24 2019 +0100
@@ -10,8 +10,6 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
-__docformat__ = 'restructuredtext'
-
 import locale
 
 from hypatia.catalog import CatalogQuery
@@ -19,7 +17,7 @@
 from hypatia.query import And, Any, NotEq, Or
 
 from pyams_catalog.query import CatalogResultSet
-from pyams_content.shared.common.interfaces import IBaseSharedTool, ISharedSite
+from pyams_content.shared.common.interfaces import IBaseSharedTool, ISharedSite, ISharedTool
 from pyams_content.zmi.interfaces import IUserAddingsMenuLabel
 from pyams_i18n.interfaces import II18n
 from pyams_skin.interfaces.viewlet import ITopLinksViewletManager
@@ -31,10 +29,14 @@
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.layer import IAdminLayer
 
+
+__docformat__ = 'restructuredtext'
+
 from pyams_content import _
 
 
-@viewlet_config(name='shared-sites.menu', layer=IAdminLayer, manager=ITopLinksViewletManager, weight=20)
+@viewlet_config(name='shared-sites.menu', layer=IAdminLayer, manager=ITopLinksViewletManager,
+                weight=20)
 class SharedSitesMenu(TopLinksViewlet):
     """Shared sites menu"""
 
@@ -48,14 +50,17 @@
         request = self.request
         parent = self.__parent__
         for site in sorted(get_all_utilities_registered_for(ISharedSite),
-                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title', request=request) or '')):
+                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title',
+                                                                                 request=request)
+                                                        or '')):
             menu = TopLinksMenu(context, request, parent, self)
             menu.label = II18n(site).query_attribute('title', request=request) or site.__name__
             menu.url = absolute_url(site, request, 'admin#dashboard.html')
             self.viewlets.append(menu)
 
 
-@viewlet_config(name='shared-contents.menu', layer=IAdminLayer, manager=ITopLinksViewletManager, weight=30)
+@viewlet_config(name='shared-contents.menu', layer=IAdminLayer, manager=ITopLinksViewletManager,
+                weight=30)
 class SharedContentsMenu(TopLinksViewlet):
     """Shared contents menu"""
 
@@ -69,7 +74,9 @@
         request = self.request
         parent = self.__parent__
         for tool in sorted(get_all_utilities_registered_for(IBaseSharedTool),
-                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title', request=request) or '')):
+                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title',
+                                                                                 request=request)
+                                                        or '')):
             if ISharedSite.providedBy(tool) or (not tool.shared_content_menu):
                 continue
             menu = TopLinksMenu(context, request, parent, self)
@@ -78,7 +85,8 @@
             self.viewlets.append(menu)
 
 
-@viewlet_config(name='shared-tools.menu', layer=IAdminLayer, manager=ITopLinksViewletManager, weight=40)
+@viewlet_config(name='shared-tools.menu', layer=IAdminLayer, manager=ITopLinksViewletManager,
+                weight=40)
 class SharedToolsMenu(TopLinksViewlet):
     """Shared tools menu"""
 
@@ -92,7 +100,9 @@
         request = self.request
         parent = self.__parent__
         for tool in sorted(get_all_utilities_registered_for(IBaseSharedTool),
-                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title', request=request) or '')):
+                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title',
+                                                                                 request=request)
+                                                        or '')):
             if ISharedSite.providedBy(tool) or tool.shared_content_menu:
                 continue
             menu = TopLinksMenu(context, request, parent, self)
@@ -101,7 +111,8 @@
             self.viewlets.append(menu)
 
 
-@viewlet_config(name='user-roles.menu', layer=IAdminLayer, manager=ITopLinksViewletManager, weight=90)
+@viewlet_config(name='user-roles.menu', layer=IAdminLayer, manager=ITopLinksViewletManager,
+                weight=90)
 class UserRolesMenu(TopLinksViewlet):
     """User roles menu"""
 
@@ -120,14 +131,17 @@
                         Any(catalog['role:pilot'], {request.principal.id})),
                      NotEq(catalog['content_type'], None))
         for tool in sorted(unique(CatalogResultSet(CatalogQuery(catalog).query(params))),
-                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title', request=request) or '')):
+                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title',
+                                                                                 request=request)
+                                                        or '')):
             menu = TopLinksMenu(context, request, parent, self)
             menu.label = II18n(tool).query_attribute('title', request=request) or tool.__name__
             menu.url = absolute_url(tool, request, 'admin#dashboard.html')
             self.viewlets.append(menu)
 
 
-@viewlet_config(name='user-addings.menu', layer=IAdminLayer, manager=ITopLinksViewletManager, weight=95)
+@viewlet_config(name='user-addings.menu', layer=IAdminLayer, manager=ITopLinksViewletManager,
+                weight=95)
 @template_config(template='templates/user-addings.pt', layer=IAdminLayer)
 class UserAddingsMenu(TopLinksViewlet):
     """User addings menu"""
@@ -146,7 +160,11 @@
         params = And(Any(catalog['role:contributor'], {request.principal.id}),
                      NotEq(catalog['content_type'], None))
         for tool in sorted(unique(CatalogResultSet(CatalogQuery(catalog).query(params))),
-                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title', request=request) or '')):
+                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title',
+                                                                                 request=request)
+                                                        or '')):
+            if not ISharedTool.providedBy(tool):
+                continue
             content_class = tool.shared_content_factory.content_class
             if content_class is None:
                 continue