Use locale to sort menu items
authorThierry Florac <thierry.florac@onf.fr>
Tue, 02 Oct 2018 09:55:36 +0200
changeset 990 3b3a47dbe205
parent 989 ba512b0e74de
child 991 5c71db179d35
Use locale to sort menu items
src/pyams_content/skin/zmi/viewlet/toplinks/__init__.py
--- a/src/pyams_content/skin/zmi/viewlet/toplinks/__init__.py	Mon Oct 01 10:13:54 2018 +0200
+++ b/src/pyams_content/skin/zmi/viewlet/toplinks/__init__.py	Tue Oct 02 09:55:36 2018 +0200
@@ -9,32 +9,29 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+import locale
+
 
 __docformat__ = 'restructuredtext'
 
 
-# import standard library
+from hypatia.catalog import CatalogQuery
+from hypatia.interfaces import ICatalog
+from hypatia.query import And, Any, NotEq, Or
 
-# import interfaces
-from hypatia.interfaces import ICatalog
+from pyams_catalog.query import CatalogResultSet
+from pyams_content import _
 from pyams_content.shared.common.interfaces import IBaseSharedTool, ISharedSite
 from pyams_content.skin.zmi.interfaces import IUserAddingsMenuLabel
 from pyams_i18n.interfaces import II18n
 from pyams_skin.interfaces.viewlet import ITopLinksViewletManager
-from pyams_zmi.layer import IAdminLayer
-
-# import packages
-from hypatia.catalog import CatalogQuery
-from hypatia.query import Any, And, Or, NotEq
-from pyams_catalog.query import CatalogResultSet
-from pyams_skin.viewlet.toplinks import TopLinksViewlet, TopLinksMenu
+from pyams_skin.viewlet.toplinks import TopLinksMenu, TopLinksViewlet
 from pyams_template.template import template_config
 from pyams_utils.list import unique
-from pyams_utils.registry import get_utility, get_all_utilities_registered_for
+from pyams_utils.registry import get_all_utilities_registered_for, get_utility
 from pyams_utils.url import absolute_url
 from pyams_viewlet.viewlet import viewlet_config
-
-from pyams_content import _
+from pyams_zmi.layer import IAdminLayer
 
 
 @viewlet_config(name='shared-sites.menu', layer=IAdminLayer, manager=ITopLinksViewletManager, weight=20)
@@ -51,7 +48,7 @@
         request = self.request
         parent = self.__parent__
         for site in sorted(get_all_utilities_registered_for(ISharedSite),
-                           key=lambda x: 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')
@@ -72,7 +69,7 @@
         request = self.request
         parent = self.__parent__
         for tool in sorted(get_all_utilities_registered_for(IBaseSharedTool),
-                           key=lambda x: 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)
@@ -95,7 +92,7 @@
         request = self.request
         parent = self.__parent__
         for tool in sorted(get_all_utilities_registered_for(IBaseSharedTool),
-                           key=lambda x: 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)
@@ -123,7 +120,7 @@
                         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: 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')
@@ -149,7 +146,7 @@
         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: II18n(x).query_attribute('title', request=request) or ''):
+                           key=lambda x: locale.strxfrm(II18n(x).query_attribute('title', request=request) or '')):
             content_class = tool.shared_content_factory.content_class
             if content_class is None:
                 continue