Commit fec61fd7 authored by Jérome Perrin's avatar Jérome Perrin

Make it possible to sort on related keys and keys from catalog table.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16812 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f351c3cc
...@@ -368,6 +368,7 @@ class SimulationTool(BaseTool): ...@@ -368,6 +368,7 @@ class SimulationTool(BaseTool):
def _generateSQLKeywordDictFromKeywordDict(self, table='stock', sql_kw={}, def _generateSQLKeywordDictFromKeywordDict(self, table='stock', sql_kw={},
new_kw={}): new_kw={}):
ctool = getToolByName(self, 'portal_catalog')
sql_kw = sql_kw.copy() sql_kw = sql_kw.copy()
new_kw = new_kw.copy() new_kw = new_kw.copy()
# Some columns cannot be found automatically, prepend table name to # Some columns cannot be found automatically, prepend table name to
...@@ -418,16 +419,19 @@ class SimulationTool(BaseTool): ...@@ -418,16 +419,19 @@ class SimulationTool(BaseTool):
simulation_query = regular_query simulation_query = regular_query
if simulation_query is not None: if simulation_query is not None:
new_kw['query'] = simulation_query new_kw['query'] = simulation_query
# Sort on # Sort on
if 'sort_on' in new_kw: if 'sort_on' in new_kw:
table_column_list = ctool.getSQLCatalog()._getCatalogSchema(
table=table)
sort_on = new_kw['sort_on'] sort_on = new_kw['sort_on']
new_sort_on = [] new_sort_on = []
for column_id, sort_direction in sort_on: for column_id, sort_direction in sort_on:
if '.' not in column_id: if column_id in table_column_list:
column_id = '%s.%s' % (table, column_id) column_id = '%s.%s' % (table, column_id)
new_sort_on.append((column_id, sort_direction)) new_sort_on.append((column_id, sort_direction))
new_kw['sort_on'] = tuple(new_sort_on) new_kw['sort_on'] = tuple(new_sort_on)
sql_kw.update(self.portal_catalog.buildSQLQuery(**new_kw)) sql_kw.update(ctool.buildSQLQuery(**new_kw))
return sql_kw return sql_kw
def _generateKeywordDict(self, def _generateKeywordDict(self,
......
...@@ -1102,6 +1102,19 @@ class TestMovementHistoryList(InventoryAPITestCase): ...@@ -1102,6 +1102,19 @@ class TestMovementHistoryList(InventoryAPITestCase):
('stock.uid', 'ascending'),)) ] ('stock.uid', 'ascending'),)) ]
self.assertEquals(movement_date_list, date_list) self.assertEquals(movement_date_list, date_list)
def test_SortOnCatalogColumn(self):
getMovementHistoryList = self.getSimulationTool().getMovementHistoryList
self._makeMovement(quantity=1, title='First')
self._makeMovement(quantity=2, title='Second')
self.assertEquals(['First', 'Second'], [ x.getObject().getTitle() for x in
getMovementHistoryList(section_uid=self.section.getUid(),
sort_on=(('title', 'ascending'),)) ])
self.assertEquals(['Second', 'First'], [ x.getObject().getTitle() for x in
getMovementHistoryList(section_uid=self.section.getUid(),
sort_on=(('title', 'descending'),)) ])
# FIXME: do we want to include it or no ? # FIXME: do we want to include it or no ?
def test_Limit(self): def test_Limit(self):
return "is it part of this API ?" # XXX return "is it part of this API ?" # XXX
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment