From 75319c0d6ae17862e7ae5fa956bb511273a8ebce Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 10 May 2022 20:06:21 -0500 Subject: [PATCH] Add grid workarounds when data is list instead of query ugh, this is not very intuitive. pretty sure all that needs an overhaul someday --- tailbone/grids/core.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tailbone/grids/core.py b/tailbone/grids/core.py index 75c2ffd5..7bc0c01d 100644 --- a/tailbone/grids/core.py +++ b/tailbone/grids/core.py @@ -596,7 +596,16 @@ class Grid(object): """ class_ = getattr(model_property, 'class_', self.model_class) column = getattr(class_, model_property.key) - return lambda q, d: q.order_by(getattr(column, d)()) + + def sorter(query, direction): + # TODO: this seems hacky..normally we expect a true query + # of course, but in some cases it may be a list instead. + # if so then we can't actually sort + if isinstance(query, list): + return query + return query.order_by(getattr(column, direction)()) + + return sorter def make_simple_sorter(self, key, foldcase=False): """ @@ -984,6 +993,16 @@ class Grid(object): return pager def make_pager(self, data): + + # TODO: this seems hacky..normally we expect `data` to be a + # query of course, but in some cases it may be a list instead. + # if so then we can't use ORM pager + if isinstance(data, list): + import paginate + return paginate.Page(data, + items_per_page=self.pagesize, + page=self.page) + return SqlalchemyOrmPage(data, items_per_page=self.pagesize, page=self.page,