[IMP] search_read: use search_read from the orm instead of rewritting it
skip search_count when getting no result from search_read remove useless test based on implementation details bzr revid: mat@openerp.com-20140117120047-9b5emsrbtjauvegl
This commit is contained in:
parent
7b2948c3bc
commit
4b7799c0c7
|
@ -1055,21 +1055,17 @@ class DataSet(http.Controller):
|
||||||
"""
|
"""
|
||||||
Model = request.session.model(model)
|
Model = request.session.model(model)
|
||||||
|
|
||||||
ids = Model.search(domain, offset or 0, limit or False, sort or False,
|
records = Model.search_read(domain, fields, offset or 0, limit or False, sort or False,
|
||||||
request.context)
|
request.context)
|
||||||
if limit and len(ids) == limit:
|
if not records:
|
||||||
|
return {
|
||||||
|
'length': 0,
|
||||||
|
'records': []
|
||||||
|
}
|
||||||
|
if limit and len(records) == limit:
|
||||||
length = Model.search_count(domain, request.context)
|
length = Model.search_count(domain, request.context)
|
||||||
else:
|
else:
|
||||||
length = len(ids) + (offset or 0)
|
length = len(records) + (offset or 0)
|
||||||
if fields and fields == ['id']:
|
|
||||||
# shortcut read if we only want the ids
|
|
||||||
return {
|
|
||||||
'length': length,
|
|
||||||
'records': [{'id': id} for id in ids]
|
|
||||||
}
|
|
||||||
|
|
||||||
records = Model.read(ids, fields or False, request.context)
|
|
||||||
records.sort(key=lambda obj: ids.index(obj['id']))
|
|
||||||
return {
|
return {
|
||||||
'length': length,
|
'length': length,
|
||||||
'records': records
|
'records': records
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from . import test_dataset, test_menu, test_serving_base, test_js
|
from . import test_menu, test_serving_base, test_js
|
||||||
|
|
||||||
fast_suite = []
|
fast_suite = []
|
||||||
checks = [
|
checks = [
|
||||||
test_dataset,
|
|
||||||
test_menu,
|
test_menu,
|
||||||
test_serving_base,
|
test_serving_base,
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from . import common
|
|
||||||
|
|
||||||
import openerp.addons.web.controllers.main
|
|
||||||
from openerp.http import request as req
|
|
||||||
|
|
||||||
class TestDataSetController(common.MockRequestCase):
|
|
||||||
def setUp(self):
|
|
||||||
super(TestDataSetController, self).setUp()
|
|
||||||
self.dataset = openerp.addons.web.controllers.main.DataSet()
|
|
||||||
self.read = req.session.model().read
|
|
||||||
self.search = req.session.model().search
|
|
||||||
|
|
||||||
def test_empty_find(self):
|
|
||||||
self.search.return_value = []
|
|
||||||
self.read.return_value = []
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
self.dataset.do_search_read('fake.model'),
|
|
||||||
{'records': [], 'length': 0})
|
|
||||||
self.read.assert_called_once_with(
|
|
||||||
[], False, req.context)
|
|
||||||
|
|
||||||
def test_regular_find(self):
|
|
||||||
self.search.return_value = [1, 2, 3]
|
|
||||||
|
|
||||||
self.dataset.do_search_read('fake.model')
|
|
||||||
self.read.assert_called_once_with(
|
|
||||||
[1, 2, 3], False, req.context)
|
|
||||||
|
|
||||||
def test_ids_shortcut(self):
|
|
||||||
self.search.return_value = [1, 2, 3]
|
|
||||||
self.read.return_value = [
|
|
||||||
{'id': 1, 'name': 'foo'},
|
|
||||||
{'id': 2, 'name': 'bar'},
|
|
||||||
{'id': 3, 'name': 'qux'}
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
self.dataset.do_search_read('fake.model', ['id']),
|
|
||||||
{'records': [{'id': 1}, {'id': 2}, {'id': 3}], 'length': 3})
|
|
||||||
self.assertFalse(self.read.called)
|
|
Loading…
Reference in New Issue