Skip to content

Commit

Permalink
Merge pull request pallets-eco#1010 from tandreas/pagination
Browse files Browse the repository at this point in the history
Abstract pagination to a different method for SQLA
  • Loading branch information
mrjoes committed Aug 22, 2015
2 parents 135b4d7 + 42e502e commit f8e62a0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions flask_admin/contrib/sqla/view.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,18 @@ def _apply_filters(self, query, count_query, joins, count_joins, filters):

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,
execute=True, page_size=None):
"""
Expand Down Expand Up @@ -948,14 +960,7 @@ def get_list(self, page, sort_column, sort_desc, search, filters,
query, joins = self._apply_sorting(query, joins, sort_column, sort_desc)

# Pagination
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)
query = self._apply_pagination(query, page, page_size)

# Execute if needed
if execute:
Expand Down

0 comments on commit f8e62a0

Please sign in to comment.