Improved query modification logic in alchemy grid views.

This commit is contained in:
Lance Edgar 2013-08-16 16:07:16 -07:00
parent 8812b74460
commit d7d7d870ab

View file

@ -39,9 +39,12 @@ __all__ = ['AlchemyGridView', 'SortableAlchemyGridView',
class AlchemyGridView(GridView):
def make_query(self):
q = Session.query(self.mapped_class)
return q
def make_query(self, session=Session):
query = session.query(self.mapped_class)
return self.modify_query(query)
def modify_query(self, query):
return query
def query(self):
return self.make_query()
@ -88,14 +91,9 @@ class SortableAlchemyGridView(AlchemyGridView):
def sort_config(self):
return self.make_sort_config(sort=self.sort)
def make_query(self):
query = Session.query(self.mapped_class)
query = grids.util.sort_query(
def modify_query(self, query):
return grids.util.sort_query(
query, self._sort_config, self.sort_map(), self.join_map())
return query
def query(self):
return self.make_query()
def make_grid(self, **kwargs):
self.update_grid_kwargs(kwargs)
@ -162,9 +160,8 @@ class SearchableAlchemyGridView(PagedAlchemyGridView):
def search_form(self):
return self.make_search_form()
def make_query(self, session=Session):
def modify_query(self, query):
join_map = self.join_map()
query = session.query(self.mapped_class)
query = grids.search.filter_query(
query, self._filter_config, self.filter_map(), join_map)
if hasattr(self, '_sort_config'):