search_global yields record instead of id
It is better for customization to yield record instead of id to prevent to instantiate a second times the record. issue4519 review6871002
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* search_global yields record instead of id
|
||||
* Add ModelTestCase
|
||||
* Add test for missing default model access
|
||||
* Report API refactorization
|
||||
|
||||
@@ -289,7 +289,7 @@ Class methods:
|
||||
|
||||
.. classmethod:: ModelStorage.search_global(cls, text)
|
||||
|
||||
Yield tuples (id, rec_name, icon) for records matching text.
|
||||
Yield tuples (record, name, icon) for records matching text.
|
||||
It is used for the global search.
|
||||
|
||||
.. classmethod:: ModelStorage.browse(ids)
|
||||
|
||||
+6
-6
@@ -170,7 +170,7 @@ class Model(ModelSQL, ModelView):
|
||||
def global_search(cls, text, limit, menu='ir.ui.menu'):
|
||||
"""
|
||||
Search on models for text including menu
|
||||
Returns a list of tuple (ratio, model, model_name, id, rec_name, icon)
|
||||
Returns a list of tuple (ratio, model, model_name, id, name, icon)
|
||||
The size of the list is limited to limit
|
||||
"""
|
||||
pool = Pool()
|
||||
@@ -196,12 +196,12 @@ class Model(ModelSQL, ModelView):
|
||||
Model = pool.get(model.model)
|
||||
if not hasattr(Model, 'search_global'):
|
||||
continue
|
||||
for id_, rec_name, icon in Model.search_global(text):
|
||||
if isinstance(rec_name, str):
|
||||
rec_name = rec_name.decode('utf-8')
|
||||
s.set_seq1(rec_name)
|
||||
for record, name, icon in Model.search_global(text):
|
||||
if isinstance(name, str):
|
||||
name = name.decode('utf-8')
|
||||
s.set_seq1(name)
|
||||
yield (s.ratio(), model.model, model.rec_name,
|
||||
id_, rec_name, icon)
|
||||
record.id, name, icon)
|
||||
return heapq.nlargest(int(limit), generate())
|
||||
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ class UIMenu(ModelSQL, ModelView):
|
||||
('rec_name', 'ilike', '%%%s%%' % text),
|
||||
]):
|
||||
if record.action:
|
||||
yield record.id, record.rec_name, record.icon
|
||||
yield record, record.rec_name, record.icon
|
||||
|
||||
@classmethod
|
||||
def search(cls, domain, offset=0, limit=None, order=None, count=False,
|
||||
|
||||
@@ -426,13 +426,13 @@ class ModelStorage(Model):
|
||||
@classmethod
|
||||
def search_global(cls, text):
|
||||
'''
|
||||
Yield tuples (id, rec_name, icon) for text
|
||||
Yield tuples (record, name, icon) for text
|
||||
'''
|
||||
# TODO improve search clause
|
||||
for record in cls.search([
|
||||
('rec_name', 'ilike', '%%%s%%' % text),
|
||||
]):
|
||||
yield record.id, record.rec_name, None
|
||||
yield record, record.rec_name, None
|
||||
|
||||
@classmethod
|
||||
def browse(cls, ids):
|
||||
|
||||
Reference in New Issue
Block a user