Sort items in top links menus
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Sep 2017 14:45:39 +0200
changeset 130 a27c1887736f
parent 129 5b02c3b2eaf2
child 131 b113d88d9ee8
Sort items in top links menus
src/pyams_content/zmi/viewlet/toplinks/__init__.py
--- a/src/pyams_content/zmi/viewlet/toplinks/__init__.py	Mon Sep 11 14:44:49 2017 +0200
+++ b/src/pyams_content/zmi/viewlet/toplinks/__init__.py	Mon Sep 11 14:45:39 2017 +0200
@@ -49,7 +49,8 @@
     def update(self):
         super(SharedSitesMenu, self).update()
         registry = get_local_registry()
-        for site in registry.getAllUtilitiesRegisteredFor(ISharedSite):
+        for site in sorted(registry.getAllUtilitiesRegisteredFor(ISharedSite),
+                           key=lambda x: II18n(x).query_attribute('title', request=self.request) or ''):
             menu = TopLinksMenu(self.context, self.request, self.__parent__, self)
             menu.label = II18n(site).query_attribute('title', request=self.request) or site.__name__
             menu.url = absolute_url(site, self.request, 'admin#dashboard.html')
@@ -67,7 +68,8 @@
     def update(self):
         super(SharedToolsMenu, self).update()
         registry = get_local_registry()
-        for tool in registry.getAllUtilitiesRegisteredFor(ISharedTool):
+        for tool in sorted(registry.getAllUtilitiesRegisteredFor(ISharedTool),
+                           key=lambda x: II18n(x).query_attribute('title', request=self.request) or ''):
             if ISharedSite.providedBy(tool):
                 continue
             menu = TopLinksMenu(self.context, self.request, self.__parent__, self)
@@ -92,7 +94,7 @@
                         Any(catalog['role:pilot'], {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)):
+                           key=lambda x: II18n(x).query_attribute('title', request=self.request) or ''):
             menu = TopLinksMenu(self.context, self.request, self.__parent__, self)
             menu.label = II18n(tool).query_attribute('title', request=self.request) or tool.__name__
             menu.url = absolute_url(tool, self.request, 'admin#dashboard.html')
@@ -115,7 +117,7 @@
         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)):
+                           key=lambda x: II18n(x).query_attribute('title', request=self.request) or ''):
             menu = TopLinksMenu(self.context, self.request, self.__parent__, self)
             adapter = registry.queryMultiAdapter((tool, self.request), IUserAddingsMenuLabel)
             if adapter is None: