Created
December 6, 2012 18:47
-
-
Save jbeluch/4227009 to your computer and use it in GitHub Desktop.
pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.