Skip to content

Commit 781ba15

Browse files
committed
Added pagination, pending to test
1 parent 807bff1 commit 781ba15

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

app/mod_photos/controllers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def photos_post():
5151
def photos_get():
5252
app.logger.debug("Applying get photos...")
5353
photos = Photo.query.all()
54+
page = request.args.get('page',1,type=int)
55+
pagination=Photo.query.paginate(page,per_page=app.config['PER_PAGE'],
56+
error_out=False)
57+
photos = pagination.items
58+
prev = None
59+
if pagination.has_prev:
60+
prev=url_for('',page=page-1,_external=True)
61+
next = None
62+
if pagination.has_next:
63+
next = url_for('',page=page+1,_external=True)
64+
5465
resp = jsonify({'data':
5566
[photo.serialize() for photo in photos]})
5667
return resp

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
UPLOAD_FOLDER='data/'
3939
MAX_CONTENT_LENGTH= 50 * 1024 * 1024
4040

41-
41+
PER_PAGE=100
4242

4343

0 commit comments

Comments
 (0)