Commit 42e502ee authored by Trevor Andreas's avatar Trevor Andreas

Abstract pagination to a different method to make it easier to override how pagination works.

parent 135b4d71
...@@ -884,6 +884,18 @@ class ModelView(BaseModelView): ...@@ -884,6 +884,18 @@ class ModelView(BaseModelView):
return query, count_query, joins, count_joins return query, count_query, joins, count_joins
def _apply_pagination(self, query, page, page_size):
if page_size is None:
page_size = self.page_size
if page_size:
query = query.limit(page_size)
if page and page_size:
query = query.offset(page * page_size)
return query
def get_list(self, page, sort_column, sort_desc, search, filters, def get_list(self, page, sort_column, sort_desc, search, filters,
execute=True, page_size=None): execute=True, page_size=None):
""" """
...@@ -948,14 +960,7 @@ class ModelView(BaseModelView): ...@@ -948,14 +960,7 @@ class ModelView(BaseModelView):
query, joins = self._apply_sorting(query, joins, sort_column, sort_desc) query, joins = self._apply_sorting(query, joins, sort_column, sort_desc)
# Pagination # Pagination
if page_size is None: query = self._apply_pagination(query, page, page_size)
page_size = self.page_size
if page_size:
query = query.limit(page_size)
if page and page_size:
query = query.offset(page * page_size)
# Execute if needed # Execute if needed
if execute: if execute:
......
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