Skip to content

Commit

Permalink
added max_per_page param to pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
kalombos committed Sep 21, 2017
1 parent 5ad6cdb commit 3aed53a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions flask_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def first_or_404(self):
abort(404)
return rv

def paginate(self, page=None, per_page=None, error_out=True):
def paginate(self, page=None, per_page=None, error_out=True, max_per_page=None):
"""Returns ``per_page`` items from page ``page``.
If no items are found and ``page`` is greater than 1, or if page is
Expand Down Expand Up @@ -465,7 +465,8 @@ def paginate(self, page=None, per_page=None, error_out=True):

per_page = 20
else:
per_page = min(per_page, 20)
if max_per_page is not None:
per_page = min(per_page, max_per_page)
else:
if page is None:
page = 1
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_query_paginate_more_than_20(app, db, Todo):

@app.route('/')
def index():
p = Todo.query.paginate()
p = Todo.query.paginate(max_per_page=20)
return '{0} items retrieved'.format(len(p.items))

c = app.test_client()
Expand Down

0 comments on commit 3aed53a

Please sign in to comment.