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,