Archetypes Vocabulary ordering in i18n interface
Huron <[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.archetypes.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
This is copy of a message that I already sent to the list earlier ... I
just had one feeback (thanks martin ;-) ) ... I'd welcome
Above all, I think this patch can be useful, I use it with great pleasure
of my users who have ordered vocabulary in their own language ...
*recopy*
I was puzzled with the fact that vocabularies (i.e. the class
Vocabulary) in archetypes was not ordered ... so I ordered when I defined my
DisplayList ... but then, when using an internationalized vocabulary, the
vacabulary was ordererd in french the was it was ordered in english ...
thus not ordered ...
I used a monkey patch (patches.py imported from __init__.py) in my
product to patch the Vocabulary class definition (in utils.py) ... here it
is, I'd welcome some feeback :
if config.PATCHVOCABULARYTOORDER:
def __init__(self, display_list, instance, i18n_domain):
self._keys = display_list._keys
self._i18n_msgids = display_list._i18n_msgids
self._values = display_list._values
self._itor = display_list._itor
self.index = display_list.index
self._instance = instance
self._i18n_domain = i18n_domain
# order it
self.orderByTranslatedValues()
def orderByTranslatedValues(self):
if len(self._values)!=0:
# get translations and order
key_trans = []
for key, (ord, value) in self._keys.items():
trans = self.getValue(key)
key_trans.append((key, trans))
key_trans.sort(lambda x,y : cmp(x[1], y[1]))
key_order = [x[0] for x in key_trans]
# order _values, _keys and _itor
for value, (ord, key) in self._values.items():
order = key_order.index(key)
self._values[value]=(order, key)
self._keys[key]=(order,value)
self._itor[order]=key
from Products.Archetypes.utils import Vocabulary
Vocabulary.__old__init__ = Vocabulary.__init__
Vocabulary.__init__ = __init__
Vocabulary.orderByTranslatedValues = orderByTranslatedValues
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click