Skip to content

Instantly share code, notes, and snippets.

@jbeluch
Created December 6, 2012 18:47
Show Gist options
  • Save jbeluch/4227009 to your computer and use it in GitHub Desktop.
Save jbeluch/4227009 to your computer and use it in GitHub Desktop.
pagination
def paginate(self, items, endpoint, is_prev=None, is_next=None,
url_args=None, finish_args=None):
url_args = url_args or {}
finish_args = finish_args or {}
is_update = True
try:
current_page = self.request.args.get('page')[0]
except TypeError:
is_update = False
current_page = 0
if is_next:
next_page = str(int(current_page) + 1)
items.insert(0, {
'label': 'Next >>',
'path': self.url_for(endpoint, page=next_page, **url_args)
})
if is_prev:
prev_page = str(int(current_page) - 1)
items.insert(0, {
'label': '<< Previous',
'path': self.url_for(endpoint, page=prev_page, **url_args)
})
return self.finish(items, update_listing=is_update, **finish_args)
@waqaspathan00
Copy link

would you mind adding comments to this? This seems like something I need to use in my project and a little help understanding it would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment