Issue #58 new

Paginate support for PyMongo & Mongokit

Mark Leyden
created an issue

Hi, I have added support for pymongo and mongokit to the paginate module attached. Perhaps you might want to add in the future?

Regards, Mark.

Comments (2)

  1. Anonymous

    Agreed, and the following from appears to do just that:

    class CursorWrapper(object):
        """Wraps the MongoDB cursor to work with the paginate module."""
        def __init__(self, cur): 
            self.cur = cur
        __iter__ = lambda self: self.cur.__iter__()
        __len__ = lambda self: self.cur.count()
        __getitem__ = lambda self, key: self.cur.__getitem__(key)
    # db query
    cursor = request.db['items'].find().sort("created", pymongo.DESCENDING)
    # paginate
    current_page = int(request.params.get("page", 1))
    items = Page(CursorWrapper(cursor), current_page, url=url_generator, 
                    items_per_page=12, item_count=cursor.count())
  2. Log in to comment