[Checkins] SVN: zope.app.container/trunk/ Used a collator for the
localized sorting of the Adding menu
Christopher Combelles
cvs-admin at zope.org
Fri Jun 13 12:54:14 EDT 2008
Log message for revision 87370:
Used a collator for the localized sorting of the Adding menu
Changed:
U zope.app.container/trunk/CHANGES.txt
U zope.app.container/trunk/src/zope/app/container/browser/adding.py
U zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py
-=-
Modified: zope.app.container/trunk/CHANGES.txt
===================================================================
--- zope.app.container/trunk/CHANGES.txt 2008-06-13 16:51:48 UTC (rev 87369)
+++ zope.app.container/trunk/CHANGES.txt 2008-06-13 16:53:53 UTC (rev 87370)
@@ -7,6 +7,7 @@
- fixed #238579 / #163149: error with unicode traversing
- fixed #221025 : adding menu is sorted with translated item
+ by using a collator (better localized sorting)
- fixed #227617 :
- prevent the namechooser from failing on '+', '@' and '/'
- added tests in the namechooser
Modified: zope.app.container/trunk/src/zope/app/container/browser/adding.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/browser/adding.py 2008-06-13 16:51:48 UTC (rev 87369)
+++ zope.app.container/trunk/src/zope/app/container/browser/adding.py 2008-06-13 16:53:53 UTC (rev 87370)
@@ -22,7 +22,7 @@
__docformat__ = 'restructuredtext'
import zope.security.checker
-from zope.component import getMultiAdapter
+from zope.component import getMultiAdapter, queryAdapter
from zope.component import getUtility
from zope.component import queryMultiAdapter
from zope.component import queryUtility
@@ -43,7 +43,8 @@
from zope.app.container.interfaces import IContainerNamesContainer
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.publisher.browser.menu import getMenu
-from zope.i18n import translate
+from zope.i18n.interfaces.locales import ICollator
+from zope.i18n.locales.fallbackcollator import FallbackCollator
class Adding(BrowserView):
implements(IAdding, IPublishTraverse)
@@ -187,7 +188,11 @@
context=self.request)
result.append(item)
- result.sort(lambda a, b: cmp(a['title'], b['title']))
+ # sort the adding info with a collator instead of a basic unicode sort
+ collator = queryAdapter(self.request.locale, ICollator)
+ if collator is None:
+ collator = FallbackCollator(self.request.locale)
+ result.sort(key = lambda x: collator.key(x['title']))
return result
def isSingleMenuItem(self):
Modified: zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py 2008-06-13 16:51:48 UTC (rev 87369)
+++ zope.app.container/trunk/src/zope/app/container/browser/tests/test_adding.py 2008-06-13 16:53:53 UTC (rev 87370)
@@ -225,7 +225,7 @@
... 'TestMenu')
>>> defineMenuItem(TestMenu, IAdding, '', 'item1')
- >>> defineMenuItem(TestMenu, IAdding, '', 'item2')
+ >>> defineMenuItem(TestMenu, IAdding, '', 'Item2')
>>> defineMenuItem(AddMenu, IAdding, '', 'item3', extra={'factory': 'f1'})
>>> defineMenuItem(AddMenu, IAdding, '', 'item4', extra={'factory': 'f2'})
@@ -272,8 +272,8 @@
3
>>> items[0]['title']
u'item1'
- >>> items[1]['title']
- u'item2'
+ >>> items[1]['title'] # the collator ordered this one correctly!
+ u'Item2'
>>> items[2]['title']
u'item3'
"""
More information about the Checkins
mailing list