How to transfer to previous page using ndb cursors?

I can not get to the "previous page" in the paging ndb.

I checked the documentation , as well as the same issue here with no success.

def show_feedback(kind, bookmark=None): """Renders returned feedback.""" cursor = None more_p= None if bookmark: cursor = Cursor(urlsafe=bookmark) q = Feedback.query() q_forward = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(-Feedback.pub_date) q_reverse = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(Feedback.pub_date) feedbacks, next_cursor, more = q_forward.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if cursor: rev_cursor = cursor.reversed() feedbacks2, prev_cursor, more_p = q_reverse.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=rev_cursor) next_bookmark = None prev_bookmark = None if more and next_cursor: next_bookmark = next_cursor.urlsafe() if more_p and prev_cursor: prev_bookmark = prev_cursor.urlsafe() return render_template_f11('show_feedback.html', kind=kind, feedbacks=feedbacks, next_bookmark=next_bookmark, prev_bookmark=prev_bookmark) 

HTML:

  {% if prev_bookmark %} <a href="{{ url_for(request.endpoint, bookmark=prev_bookmark) }}">Previous</a> {% endif %} {% if next_bookmark %} <a href="{{ url_for(request.endpoint, bookmark=next_bookmark) }}">Next</a> {% endif %} 

I can properly forward to the end of the page. But I can not do the opposite page to the last page, and even then I can not go back to the first page.

What am I missing, please?

UPDATE:

Changed the code with the offers of Faisal. I have to admit, it works better. But paging does not work properly:

I have 7 records. PAGE_SIZE in config is 3. Therefore, we get three pages:

When I click Next, I get 7.6.5 → 4.3.2 → 1 Perfect. Now when you press the previous (?) 1 → 3,4,5 → 5,6,7 (?)

thanks for the help

 def show_feedback(kind, bookmark=None): """Renders returned feedback.""" is_prev = request.args.get('prev', False) cursor = None if bookmark: cursor = Cursor(urlsafe=bookmark) q = Feedback.query() q_forward = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(-Feedback.pub_date) q_reverse = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(Feedback.pub_date) qry = q_reverse if is_prev else q_forward feedbacks, cursor, more = qry.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if is_prev: prev_bookmark = cursor.reversed().urlsafe() if more else None next_bookmark = bookmark else: prev_bookmark = bookmark next_bookmark = cursor.urlsafe() if more else None return render_template_f11('show_feedback.html', kind=kind, feedbacks=feedbacks, next_bookmark=next_bookmark, prev_bookmark=prev_bookmark) ): def show_feedback(kind, bookmark=None): """Renders returned feedback.""" is_prev = request.args.get('prev', False) cursor = None if bookmark: cursor = Cursor(urlsafe=bookmark) q = Feedback.query() q_forward = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(-Feedback.pub_date) q_reverse = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(Feedback.pub_date) qry = q_reverse if is_prev else q_forward feedbacks, cursor, more = qry.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if is_prev: prev_bookmark = cursor.reversed().urlsafe() if more else None next_bookmark = bookmark else: prev_bookmark = bookmark next_bookmark = cursor.urlsafe() if more else None return render_template_f11('show_feedback.html', kind=kind, feedbacks=feedbacks, next_bookmark=next_bookmark, prev_bookmark=prev_bookmark) kind]). order (-Feedback.pub_date) def show_feedback(kind, bookmark=None): """Renders returned feedback.""" is_prev = request.args.get('prev', False) cursor = None if bookmark: cursor = Cursor(urlsafe=bookmark) q = Feedback.query() q_forward = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(-Feedback.pub_date) q_reverse = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(Feedback.pub_date) qry = q_reverse if is_prev else q_forward feedbacks, cursor, more = qry.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if is_prev: prev_bookmark = cursor.reversed().urlsafe() if more else None next_bookmark = bookmark else: prev_bookmark = bookmark next_bookmark = cursor.urlsafe() if more else None return render_template_f11('show_feedback.html', kind=kind, feedbacks=feedbacks, next_bookmark=next_bookmark, prev_bookmark=prev_bookmark) kind]). order (Feedback.pub_date) def show_feedback(kind, bookmark=None): """Renders returned feedback.""" is_prev = request.args.get('prev', False) cursor = None if bookmark: cursor = Cursor(urlsafe=bookmark) q = Feedback.query() q_forward = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(-Feedback.pub_date) q_reverse = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(Feedback.pub_date) qry = q_reverse if is_prev else q_forward feedbacks, cursor, more = qry.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if is_prev: prev_bookmark = cursor.reversed().urlsafe() if more else None next_bookmark = bookmark else: prev_bookmark = bookmark next_bookmark = cursor.urlsafe() if more else None return render_template_f11('show_feedback.html', kind=kind, feedbacks=feedbacks, next_bookmark=next_bookmark, prev_bookmark=prev_bookmark) app.config [ 'FEEDBACK_PER_PAGE'], start_cursor = cursor) def show_feedback(kind, bookmark=None): """Renders returned feedback.""" is_prev = request.args.get('prev', False) cursor = None if bookmark: cursor = Cursor(urlsafe=bookmark) q = Feedback.query() q_forward = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(-Feedback.pub_date) q_reverse = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(Feedback.pub_date) qry = q_reverse if is_prev else q_forward feedbacks, cursor, more = qry.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if is_prev: prev_bookmark = cursor.reversed().urlsafe() if more else None next_bookmark = bookmark else: prev_bookmark = bookmark next_bookmark = cursor.urlsafe() if more else None return render_template_f11('show_feedback.html', kind=kind, feedbacks=feedbacks, next_bookmark=next_bookmark, prev_bookmark=prev_bookmark) ) if more else None def show_feedback(kind, bookmark=None): """Renders returned feedback.""" is_prev = request.args.get('prev', False) cursor = None if bookmark: cursor = Cursor(urlsafe=bookmark) q = Feedback.query() q_forward = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(-Feedback.pub_date) q_reverse = q.filter(Feedback.kind==Feedback.KINDS[kind]).order(Feedback.pub_date) qry = q_reverse if is_prev else q_forward feedbacks, cursor, more = qry.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if is_prev: prev_bookmark = cursor.reversed().urlsafe() if more else None next_bookmark = bookmark else: prev_bookmark = bookmark next_bookmark = cursor.urlsafe() if more else None return render_template_f11('show_feedback.html', kind=kind, feedbacks=feedbacks, next_bookmark=next_bookmark, prev_bookmark=prev_bookmark) 

UPDATE 2:

Now he works with almost reverse ().

7.6.5 → next → 4.3.2 → next → 1

1 → prev → 2,3,4 → 5,6,7 (Order is not the first day of the last date)

+7
google-app-engine paging cursor app-engine-ndb
source share
2 answers

So, here I am using the current bookmark for navigation for the next or previous one and deleting another request so that it does not request twice for each request. (The old description was edited / the answer was incorrect when I tested it. This works on my localhost).

Try:

 is_prev = self.request.get('prev', False) if is_prev: qry = q_reverse cursor = cursor.reversed() else: qry = q_forward feedbacks, cursor, more = qry.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if is_prev: prev_bookmark = cursor.reversed().urlsafe() if more else None next_bookmark = bookmark else: prev_bookmark = bookmark next_bookmark = cursor.urlsafe() if more else None app.config [ 'FEEDBACK_PER_PAGE'], start_cursor = cursor) is_prev = self.request.get('prev', False) if is_prev: qry = q_reverse cursor = cursor.reversed() else: qry = q_forward feedbacks, cursor, more = qry.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if is_prev: prev_bookmark = cursor.reversed().urlsafe() if more else None next_bookmark = bookmark else: prev_bookmark = bookmark next_bookmark = cursor.urlsafe() if more else None ) if more else None is_prev = self.request.get('prev', False) if is_prev: qry = q_reverse cursor = cursor.reversed() else: qry = q_forward feedbacks, cursor, more = qry.fetch_page(app.config['FEEDBACK_PER_PAGE'], start_cursor=cursor) if is_prev: prev_bookmark = cursor.reversed().urlsafe() if more else None next_bookmark = bookmark else: prev_bookmark = bookmark next_bookmark = cursor.urlsafe() if more else None 

HTML

 {% if prev_bookmark %} <a href="{{ url_for(request.endpoint, bookmark=prev_bookmark, prev=True) }}">Previous</a> {% endif %} {% if next_bookmark %} <a href="{{ url_for(request.endpoint, bookmark=next_bookmark) }}">Next</a> {% endif %} 
+9
source share

Here you have a complete working solution. In your code, something is wrong.

They are key - to reverse the results in the reverse direction. It's complicated.

Here you have:

 def return_query_page(query_class, size=10, bookmark=None, is_prev=None, equality_filters=None, orders=None): """ Generate a paginated result on any class Param query_class: The ndb model class to query Param size: The size of the results Param bokkmark: The urlsafe cursor of the previous queries. First time will be None Param is_prev: If your requesting for a next result or the previous ones Param equal_filters: a dictionary of {'property': value} to apply equality filters only Param orders: a dictionary of {'property': '-' or ''} to order the results like .order(cls.property) Return: a tuple (list of results, Previous cursor bookmark, Next cursor bookmark) """ if bookmark: cursor = ndb.Cursor(urlsafe=bookmark) else: is_prev = None cursor = None q = query_class.query() try: for prop, value in equality_filters.iteritems(): q = q.filter(getattr(query_class, prop) == value) q_forward = q.filter() q_reverse = q.filter() for prop, value in orders.iteritems(): if value == '-': q_forward = q_forward.order(-getattr(query_class, prop)) q_reverse = q_reverse.order(getattr(query_class, prop)) else: q_forward = q_forward.order(getattr(query_class, prop)) q_reverse = q_reverse.order(-getattr(query_class, prop)) except: return None, None, None if is_prev: qry = q_reverse new_cursor = cursor.reversed() if cursor else None else: qry = q_forward new_cursor = cursor if cursor else None results, new_cursor, more = qry.fetch_page(size, start_cursor=new_cursor) if more and new_cursor: more = True else: more = False if is_prev: prev_bookmark = new_cursor.reversed().urlsafe() if more else None next_bookmark = bookmark results.reverse() else: prev_bookmark = bookmark next_bookmark = new_cursor.urlsafe() if more else None return results, prev_bookmark, next_bookmark , equality_filters = None, orders = None): def return_query_page(query_class, size=10, bookmark=None, is_prev=None, equality_filters=None, orders=None): """ Generate a paginated result on any class Param query_class: The ndb model class to query Param size: The size of the results Param bokkmark: The urlsafe cursor of the previous queries. First time will be None Param is_prev: If your requesting for a next result or the previous ones Param equal_filters: a dictionary of {'property': value} to apply equality filters only Param orders: a dictionary of {'property': '-' or ''} to order the results like .order(cls.property) Return: a tuple (list of results, Previous cursor bookmark, Next cursor bookmark) """ if bookmark: cursor = ndb.Cursor(urlsafe=bookmark) else: is_prev = None cursor = None q = query_class.query() try: for prop, value in equality_filters.iteritems(): q = q.filter(getattr(query_class, prop) == value) q_forward = q.filter() q_reverse = q.filter() for prop, value in orders.iteritems(): if value == '-': q_forward = q_forward.order(-getattr(query_class, prop)) q_reverse = q_reverse.order(getattr(query_class, prop)) else: q_forward = q_forward.order(getattr(query_class, prop)) q_reverse = q_reverse.order(-getattr(query_class, prop)) except: return None, None, None if is_prev: qry = q_reverse new_cursor = cursor.reversed() if cursor else None else: qry = q_forward new_cursor = cursor if cursor else None results, new_cursor, more = qry.fetch_page(size, start_cursor=new_cursor) if more and new_cursor: more = True else: more = False if is_prev: prev_bookmark = new_cursor.reversed().urlsafe() if more else None next_bookmark = bookmark results.reverse() else: prev_bookmark = bookmark next_bookmark = new_cursor.urlsafe() if more else None return results, prev_bookmark, next_bookmark property': value} to apply equality filters only def return_query_page(query_class, size=10, bookmark=None, is_prev=None, equality_filters=None, orders=None): """ Generate a paginated result on any class Param query_class: The ndb model class to query Param size: The size of the results Param bokkmark: The urlsafe cursor of the previous queries. First time will be None Param is_prev: If your requesting for a next result or the previous ones Param equal_filters: a dictionary of {'property': value} to apply equality filters only Param orders: a dictionary of {'property': '-' or ''} to order the results like .order(cls.property) Return: a tuple (list of results, Previous cursor bookmark, Next cursor bookmark) """ if bookmark: cursor = ndb.Cursor(urlsafe=bookmark) else: is_prev = None cursor = None q = query_class.query() try: for prop, value in equality_filters.iteritems(): q = q.filter(getattr(query_class, prop) == value) q_forward = q.filter() q_reverse = q.filter() for prop, value in orders.iteritems(): if value == '-': q_forward = q_forward.order(-getattr(query_class, prop)) q_reverse = q_reverse.order(getattr(query_class, prop)) else: q_forward = q_forward.order(getattr(query_class, prop)) q_reverse = q_reverse.order(-getattr(query_class, prop)) except: return None, None, None if is_prev: qry = q_reverse new_cursor = cursor.reversed() if cursor else None else: qry = q_forward new_cursor = cursor if cursor else None results, new_cursor, more = qry.fetch_page(size, start_cursor=new_cursor) if more and new_cursor: more = True else: more = False if is_prev: prev_bookmark = new_cursor.reversed().urlsafe() if more else None next_bookmark = bookmark results.reverse() else: prev_bookmark = bookmark next_bookmark = new_cursor.urlsafe() if more else None return results, prev_bookmark, next_bookmark prop) == value) def return_query_page(query_class, size=10, bookmark=None, is_prev=None, equality_filters=None, orders=None): """ Generate a paginated result on any class Param query_class: The ndb model class to query Param size: The size of the results Param bokkmark: The urlsafe cursor of the previous queries. First time will be None Param is_prev: If your requesting for a next result or the previous ones Param equal_filters: a dictionary of {'property': value} to apply equality filters only Param orders: a dictionary of {'property': '-' or ''} to order the results like .order(cls.property) Return: a tuple (list of results, Previous cursor bookmark, Next cursor bookmark) """ if bookmark: cursor = ndb.Cursor(urlsafe=bookmark) else: is_prev = None cursor = None q = query_class.query() try: for prop, value in equality_filters.iteritems(): q = q.filter(getattr(query_class, prop) == value) q_forward = q.filter() q_reverse = q.filter() for prop, value in orders.iteritems(): if value == '-': q_forward = q_forward.order(-getattr(query_class, prop)) q_reverse = q_reverse.order(getattr(query_class, prop)) else: q_forward = q_forward.order(getattr(query_class, prop)) q_reverse = q_reverse.order(-getattr(query_class, prop)) except: return None, None, None if is_prev: qry = q_reverse new_cursor = cursor.reversed() if cursor else None else: qry = q_forward new_cursor = cursor if cursor else None results, new_cursor, more = qry.fetch_page(size, start_cursor=new_cursor) if more and new_cursor: more = True else: more = False if is_prev: prev_bookmark = new_cursor.reversed().urlsafe() if more else None next_bookmark = bookmark results.reverse() else: prev_bookmark = bookmark next_bookmark = new_cursor.urlsafe() if more else None return results, prev_bookmark, next_bookmark prop)) def return_query_page(query_class, size=10, bookmark=None, is_prev=None, equality_filters=None, orders=None): """ Generate a paginated result on any class Param query_class: The ndb model class to query Param size: The size of the results Param bokkmark: The urlsafe cursor of the previous queries. First time will be None Param is_prev: If your requesting for a next result or the previous ones Param equal_filters: a dictionary of {'property': value} to apply equality filters only Param orders: a dictionary of {'property': '-' or ''} to order the results like .order(cls.property) Return: a tuple (list of results, Previous cursor bookmark, Next cursor bookmark) """ if bookmark: cursor = ndb.Cursor(urlsafe=bookmark) else: is_prev = None cursor = None q = query_class.query() try: for prop, value in equality_filters.iteritems(): q = q.filter(getattr(query_class, prop) == value) q_forward = q.filter() q_reverse = q.filter() for prop, value in orders.iteritems(): if value == '-': q_forward = q_forward.order(-getattr(query_class, prop)) q_reverse = q_reverse.order(getattr(query_class, prop)) else: q_forward = q_forward.order(getattr(query_class, prop)) q_reverse = q_reverse.order(-getattr(query_class, prop)) except: return None, None, None if is_prev: qry = q_reverse new_cursor = cursor.reversed() if cursor else None else: qry = q_forward new_cursor = cursor if cursor else None results, new_cursor, more = qry.fetch_page(size, start_cursor=new_cursor) if more and new_cursor: more = True else: more = False if is_prev: prev_bookmark = new_cursor.reversed().urlsafe() if more else None next_bookmark = bookmark results.reverse() else: prev_bookmark = bookmark next_bookmark = new_cursor.urlsafe() if more else None return results, prev_bookmark, next_bookmark prop)) def return_query_page(query_class, size=10, bookmark=None, is_prev=None, equality_filters=None, orders=None): """ Generate a paginated result on any class Param query_class: The ndb model class to query Param size: The size of the results Param bokkmark: The urlsafe cursor of the previous queries. First time will be None Param is_prev: If your requesting for a next result or the previous ones Param equal_filters: a dictionary of {'property': value} to apply equality filters only Param orders: a dictionary of {'property': '-' or ''} to order the results like .order(cls.property) Return: a tuple (list of results, Previous cursor bookmark, Next cursor bookmark) """ if bookmark: cursor = ndb.Cursor(urlsafe=bookmark) else: is_prev = None cursor = None q = query_class.query() try: for prop, value in equality_filters.iteritems(): q = q.filter(getattr(query_class, prop) == value) q_forward = q.filter() q_reverse = q.filter() for prop, value in orders.iteritems(): if value == '-': q_forward = q_forward.order(-getattr(query_class, prop)) q_reverse = q_reverse.order(getattr(query_class, prop)) else: q_forward = q_forward.order(getattr(query_class, prop)) q_reverse = q_reverse.order(-getattr(query_class, prop)) except: return None, None, None if is_prev: qry = q_reverse new_cursor = cursor.reversed() if cursor else None else: qry = q_forward new_cursor = cursor if cursor else None results, new_cursor, more = qry.fetch_page(size, start_cursor=new_cursor) if more and new_cursor: more = True else: more = False if is_prev: prev_bookmark = new_cursor.reversed().urlsafe() if more else None next_bookmark = bookmark results.reverse() else: prev_bookmark = bookmark next_bookmark = new_cursor.urlsafe() if more else None return results, prev_bookmark, next_bookmark prop)) def return_query_page(query_class, size=10, bookmark=None, is_prev=None, equality_filters=None, orders=None): """ Generate a paginated result on any class Param query_class: The ndb model class to query Param size: The size of the results Param bokkmark: The urlsafe cursor of the previous queries. First time will be None Param is_prev: If your requesting for a next result or the previous ones Param equal_filters: a dictionary of {'property': value} to apply equality filters only Param orders: a dictionary of {'property': '-' or ''} to order the results like .order(cls.property) Return: a tuple (list of results, Previous cursor bookmark, Next cursor bookmark) """ if bookmark: cursor = ndb.Cursor(urlsafe=bookmark) else: is_prev = None cursor = None q = query_class.query() try: for prop, value in equality_filters.iteritems(): q = q.filter(getattr(query_class, prop) == value) q_forward = q.filter() q_reverse = q.filter() for prop, value in orders.iteritems(): if value == '-': q_forward = q_forward.order(-getattr(query_class, prop)) q_reverse = q_reverse.order(getattr(query_class, prop)) else: q_forward = q_forward.order(getattr(query_class, prop)) q_reverse = q_reverse.order(-getattr(query_class, prop)) except: return None, None, None if is_prev: qry = q_reverse new_cursor = cursor.reversed() if cursor else None else: qry = q_forward new_cursor = cursor if cursor else None results, new_cursor, more = qry.fetch_page(size, start_cursor=new_cursor) if more and new_cursor: more = True else: more = False if is_prev: prev_bookmark = new_cursor.reversed().urlsafe() if more else None next_bookmark = bookmark results.reverse() else: prev_bookmark = bookmark next_bookmark = new_cursor.urlsafe() if more else None return results, prev_bookmark, next_bookmark prop)) def return_query_page(query_class, size=10, bookmark=None, is_prev=None, equality_filters=None, orders=None): """ Generate a paginated result on any class Param query_class: The ndb model class to query Param size: The size of the results Param bokkmark: The urlsafe cursor of the previous queries. First time will be None Param is_prev: If your requesting for a next result or the previous ones Param equal_filters: a dictionary of {'property': value} to apply equality filters only Param orders: a dictionary of {'property': '-' or ''} to order the results like .order(cls.property) Return: a tuple (list of results, Previous cursor bookmark, Next cursor bookmark) """ if bookmark: cursor = ndb.Cursor(urlsafe=bookmark) else: is_prev = None cursor = None q = query_class.query() try: for prop, value in equality_filters.iteritems(): q = q.filter(getattr(query_class, prop) == value) q_forward = q.filter() q_reverse = q.filter() for prop, value in orders.iteritems(): if value == '-': q_forward = q_forward.order(-getattr(query_class, prop)) q_reverse = q_reverse.order(getattr(query_class, prop)) else: q_forward = q_forward.order(getattr(query_class, prop)) q_reverse = q_reverse.order(-getattr(query_class, prop)) except: return None, None, None if is_prev: qry = q_reverse new_cursor = cursor.reversed() if cursor else None else: qry = q_forward new_cursor = cursor if cursor else None results, new_cursor, more = qry.fetch_page(size, start_cursor=new_cursor) if more and new_cursor: more = True else: more = False if is_prev: prev_bookmark = new_cursor.reversed().urlsafe() if more else None next_bookmark = bookmark results.reverse() else: prev_bookmark = bookmark next_bookmark = new_cursor.urlsafe() if more else None return results, prev_bookmark, next_bookmark ) if more else None def return_query_page(query_class, size=10, bookmark=None, is_prev=None, equality_filters=None, orders=None): """ Generate a paginated result on any class Param query_class: The ndb model class to query Param size: The size of the results Param bokkmark: The urlsafe cursor of the previous queries. First time will be None Param is_prev: If your requesting for a next result or the previous ones Param equal_filters: a dictionary of {'property': value} to apply equality filters only Param orders: a dictionary of {'property': '-' or ''} to order the results like .order(cls.property) Return: a tuple (list of results, Previous cursor bookmark, Next cursor bookmark) """ if bookmark: cursor = ndb.Cursor(urlsafe=bookmark) else: is_prev = None cursor = None q = query_class.query() try: for prop, value in equality_filters.iteritems(): q = q.filter(getattr(query_class, prop) == value) q_forward = q.filter() q_reverse = q.filter() for prop, value in orders.iteritems(): if value == '-': q_forward = q_forward.order(-getattr(query_class, prop)) q_reverse = q_reverse.order(getattr(query_class, prop)) else: q_forward = q_forward.order(getattr(query_class, prop)) q_reverse = q_reverse.order(-getattr(query_class, prop)) except: return None, None, None if is_prev: qry = q_reverse new_cursor = cursor.reversed() if cursor else None else: qry = q_forward new_cursor = cursor if cursor else None results, new_cursor, more = qry.fetch_page(size, start_cursor=new_cursor) if more and new_cursor: more = True else: more = False if is_prev: prev_bookmark = new_cursor.reversed().urlsafe() if more else None next_bookmark = bookmark results.reverse() else: prev_bookmark = bookmark next_bookmark = new_cursor.urlsafe() if more else None return results, prev_bookmark, next_bookmark 

This is a link to the github project: https://github.com/janscas/ndb-gae-pagination

0
source share

All Articles