mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 15:35:46 +07:00
[IMP] *: client side sorted implementation
Allow sorting by a callback. Sort remains client-side.
This commit is contained in:
parent
d748d4b215
commit
aefbdaf974
10
conftest.py
10
conftest.py
@ -1185,9 +1185,13 @@ class Model:
|
||||
|
||||
# because sorted is not xmlrpc-compatible (it doesn't downgrade properly)
|
||||
def sorted(self, field):
|
||||
rs = self.read([field])
|
||||
rs.sort(key=lambda r: r[field])
|
||||
return Model(self._env, self._model, [r['id'] for r in rs])
|
||||
fn = field if callable(field) else lambda r: r[field]
|
||||
|
||||
return Model(self._env, self._model, (
|
||||
id
|
||||
for record in sorted(self, key=fn)
|
||||
for id in record.ids
|
||||
))
|
||||
|
||||
def __getitem__(self, index):
|
||||
if isinstance(index, str):
|
||||
|
Loading…
Reference in New Issue
Block a user