Commit 53c4361d authored by Christophe Combelles's avatar Christophe Combelles

Used a collator for the localized sorting of the Adding menu

parent d882d96d
......@@ -7,6 +7,7 @@ CHANGES
- 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
......
......@@ -22,7 +22,7 @@ $Id$
__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 IAdding, INameChooser
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 @@ class Adding(BrowserView):
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):
......
......@@ -225,7 +225,7 @@ def test_constraint_driven_addingInfo():
... '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 @@ def test_constraint_driven_addingInfo():
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'
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment