From 127f7a8d913c91e70e37b81f1411834bb203e2f6 Mon Sep 17 00:00:00 2001 From: fpeters <> Date: Sun, 9 May 2004 08:01:03 +0000 Subject: [PATCH] =?UTF-8?q?param=C3=A8tre=20'sort'=20=C3=A0=20getObjectIds?= =?UTF-8?q?WithCriteria?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/proxy/ObjectsProxy.py | 10 +++++----- shared/server/ObjectsServer.py | 11 +++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/shared/proxy/ObjectsProxy.py b/shared/proxy/ObjectsProxy.py index 793e671c..6e4f9df2 100644 --- a/shared/proxy/ObjectsProxy.py +++ b/shared/proxy/ObjectsProxy.py @@ -1170,13 +1170,13 @@ class ObjectsProxy(ObjectsCommonMixin, AdministrableProxyMixin, Proxy): return result - def getObjectIdsWithCriteria(self, criteria, serverId = None): + def getObjectIdsWithCriteria(self, criteria, sort = '', serverId = None): userToken = context.getVar('userToken', default = '') serverId = self.getServerId(serverId = serverId) return callServer( serverId, 'getObjectIdsWithCriteria', - [serverId, getApplicationToken(), userToken, criteria]) + [serverId, getApplicationToken(), userToken, criteria, sort]) def getObjectLabelAndLanguage(self, objectId, multiCall = None): """Retrieve the object label and language in sequence. @@ -1452,10 +1452,10 @@ class ObjectsProxy(ObjectsCommonMixin, AdministrableProxyMixin, Proxy): objects[objectIds[i]] = lazyObjects[i]() return objects - def getObjectsWithCriteria(self, criteria, requiredSlotNames = None, - serverId = None): + def getObjectsWithCriteria(self, criteria, sort = '', + requiredSlotNames = None, serverId = None): objectIds = self.getObjectIdsWithCriteria( - criteria, serverId = serverId) + criteria, sort, serverId = serverId) multiCall = MultiCall() for objectId in objectIds: self.getPartialObject( diff --git a/shared/server/ObjectsServer.py b/shared/server/ObjectsServer.py index ab0b0d85..29768f45 100644 --- a/shared/server/ObjectsServer.py +++ b/shared/server/ObjectsServer.py @@ -2292,11 +2292,18 @@ class ObjectsServer(AdministrableServerMixin, Server): result.append(objectId) return result - def getObjectIdsWithCriteria(self, criteria): + def getObjectIdsWithCriteria(self, criteria, sort): virtualServerId = context.getVar('applicationId') virtualServer = self.getVirtualServer(virtualServerId) result = [] - for objectId, objectCore in virtualServer.objects.items(): + items = virtualServer.objects.items() + if sort: + reverse = 0 + if sort[0] == '-': + sort = sort[1:] + reverse = 1 + items.sort(lambda x,y: cmp(getattr(x[1], sort), getattr(y[1], sort))) + for objectId, objectCore in items: if not self.canGetObject(objectId): continue try: