Commit eb65c443 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Use sortValueList in ERP5Type.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4097 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fa735988
......@@ -36,6 +36,7 @@ from Products.ERP5Type import Permissions
from Products.ERP5Type import PropertySheet
from Products.ERP5Type.Document.Folder import Folder
from Products.CMFCategory.Renderer import Renderer
from Products.ERP5Type.Utils import sortValueList
from zLOG import LOG
......@@ -168,41 +169,6 @@ class Category(Folder):
logical_title_list.append(logical_title)
return '/'.join(logical_title_list)
def _sortCategoryValueList(self, value_list=(), sort_on=None, sort_order=None, **kw):
"""Sort categories.
"""
# Sorting.
if sort_on is not None:
if type(sort_on) == type(''):
sort_on = (sort_on,)
reverse = (sort_order in ('descending', 'reverse', 'DESC'))
new_sort_on = []
for key in sort_on:
if type(key) == type(''):
new_sort_on.append((key, reverse, None))
else:
if len(key) == 1:
new_sort_on.append((key[0], reverse, None))
else:
new_sort_on.append((key[0],
key[1] in ('descending', 'reverse', 'DESC'),
len(key) > 2 and ken[2] or None))
sort_on = new_sort_on
def sort_categories(a, b):
result = 0
for key, reverse, as_type in sort_on:
# FIXME: as_type is ignored.
result = cmp(a.getProperty(key, None), b.getProperty(key, None))
if reverse:
result = -result
if result != 0:
break
return result
value_list.sort(sort_categories)
return value_list
security.declareProtected(Permissions.AccessContentsInformation,
'getCategoryChildValueList')
def getCategoryChildValueList(self, recursive=1, include_if_child=1, sort_on=None, sort_order=None, **kw):
......@@ -235,7 +201,7 @@ class Category(Folder):
for c in self.objectValues(self.allowed_types):
value_list.append(c)
return self._sortCategoryValueList(value_list=value_list, sort_on=sort_on, sort_order=sort_order, **kw)
return sortValueList(value_list, sort_on, sort_order, **kw)
# List names recursively
security.declareProtected(Permissions.AccessContentsInformation,
......@@ -581,7 +547,7 @@ class BaseCategory(Category):
else:
if len(c.objectValues(self.allowed_types))==0:
value_list.append(c)
return self._sortCategoryValueList(value_list=value_list, sort_on=sort_on, sort_order=sort_order)
return sortValueList(value_list, sort_on, sort_order, **kw)
# Alias for compatibility
security.declareProtected( Permissions.AccessContentsInformation, 'getBaseCategory' )
......
......@@ -38,6 +38,7 @@ from Products.ERP5Type.CopySupport import CopyContainer
from Products.ERP5Type import PropertySheet, Permissions
from Products.ERP5Type.XMLExportImport import Folder_asXML
from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.Utils import sortValueList
from Products.BTreeFolder2.CMFBTreeFolder import CMFBTreeFolder
......@@ -696,7 +697,7 @@ be a problem)."""
return corrected_list
security.declareProtected( Permissions.AccessContentsInformation, 'objectValues' )
def objectValues(self, spec=None, meta_type=None, portal_type=None, sort_on=None, **kw):
def objectValues(self, spec=None, meta_type=None, portal_type=None, sort_on=None, sort_order=None, **kw):
#LOG('objectValues', 0, 'spec = %r, kw = %r' % (spec, kw))
if meta_type is not None:
spec = meta_type
......@@ -705,15 +706,9 @@ be a problem)."""
if type(portal_type) == type(''):
portal_type = (portal_type,)
object_list = filter(lambda x: x.getPortalType() in portal_type, object_list)
if sort_on is not None:
def cmpObjects(x, y):
for id, title in sort_on:
result = cmp(x.getProperty(id), y.getProperty(id))
if result != 0:
return result
return 0
object_list.sort(cmpObjects)
object_list = sortValueList(object_list, sort_on, sort_order, **kw)
return object_list
# Override security declaration of CMFCore/PortalFolder (used by CMFBTreeFolder)
......
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