Pagination Issues
goojo opened this issue · comments
I've had to make a number of tweaks to get pagnation.py working, here's what I had to do, I'm not sure if these are bugs or just differences in setup, I'm working on the assumption here that "collection" variable passed to pagination is a mongo cursor?
has_next:
return True if (self.page.count(True) == self.limit) else False
return True if (len(self.page) == self.limit) else False
I was getting an exception on trying to get the length of len(self.page) (Mongo Cursor), one issue with the change I made was that it could only be called prior to iterating over the cursor.
NEXT:
__build_url:
page_str = "page=%d" % page_num
return re.sub(r'page=\d+', page_str, url)
page_str = "&page=%d" % page_num
return re.sub(r'&page=\d+', page_str, url)
I had an issue if "page" as the only argument, the _build_url func was assuming that you had something else eg: "?foo=true%page=2" so removing the & seemed to solve this issue.
Hope this helps. (New to Github, and having some issues with the mark up)
Thanks for the heads up. Added your fixes in. Also added a rewind on the cursor before the count to address the issue you pointed out re cursors that have already been iterated over. Glad to see you have been working with the framework. Feel free to fork a copy of the source and submit patches as pull requests. Grateful for any and all help. :)
Still getting used to git but think I've just forked and done a fix on an import. Going to try the latest changes with the cursor rewind now.
thx
John
sweet man. git is a weird and wonderful tool. takes a bit of getting used to for sure. post a follow up comment to let me know how paging updates work out for you.