[IMP] Cleaned do_search_read.

bzr revid: nicolas.vanhoren@openerp.com-20110513133914-nvezbww1r84mpiju
This commit is contained in:
niv-openerp 2011-05-13 15:39:14 +02:00
parent 4702007c37
commit 5f11a9f30c
1 changed files with 25 additions and 3 deletions

View File

@ -329,7 +329,7 @@ class DataSet(openerpweb.Controller):
@openerpweb.jsonrequest
def search_read(self, request, model, fields=False, offset=0, limit=False, domain=None, context=None, sort=None):
return self.do_search_read(request, model, fields, offset, limit, domain, context, sort)
def do_search_read(self, request, model, fields=False, offset=0, limit=False, domain=None, context=None, sort=None, ids=False):
def do_search_read(self, request, model, fields=False, offset=0, limit=False, domain=None, context=None, sort=None):
""" Performs a search() followed by a read() (if needed) using the
provided search criteria
@ -346,8 +346,8 @@ class DataSet(openerpweb.Controller):
:rtype: list
"""
Model = request.session.model(model)
if not ids:
ids = Model.search(domain or [], offset or 0, limit or False,
ids = Model.search(domain or [], offset or 0, limit or False,
sort or False, request.context)
if fields and fields == ['id']:
@ -357,6 +357,28 @@ class DataSet(openerpweb.Controller):
reads = Model.read(ids, fields or False, request.context)
reads.sort(key=lambda obj: ids.index(obj['id']))
return reads
@openerpweb.jsonrequest
def read(self, request, model, ids, fields=False):
return self.do_search_read(request, model, ids, fields)
def search_read(self, request, model, ids, fields=False):
""" Performs a read()
:param request: a JSON-RPC request object
:type request: openerpweb.JsonRequest
:param str model: the name of the model to search on
:param ids: the ids of the records
:type ids: [?]
:param fields: a list of the fields to return in the result records
:type fields: [str]
:returns: a list of result records
:rtype: list
"""
Model = request.session.model(model)
reads = Model.read(ids, fields or False, request.context)
reads.sort(key=lambda obj: ids.index(obj['id']))
return reads
@openerpweb.jsonrequest
def get(self, request, model, ids, fields=False):