@classmethod def get_page(cls, app_id, bookmark=None): pagesize = 15 first_fetch = not bookmark if first_fetch: ascending = False date = None elif bookmark.startswith('-'): # we're moving backwards ascending = False date = str_to_date(bookmark[1:]) else: ascending = True date = str_to_date(bookmark) FOO = Transaction.app_id(app_id).order('date' if ascending else '-date') if date: filter_op = '<=' if ascending else '>' FOO = FOO.filter('date ' + filter_op, date) transactions = FOO.fetch(pagesize + 1) more = len(transactions) == pagesize+1 less = not first_fetch if more: # we have one more page to show next = transactions[-1].date transactions = transactions[:pagesize] else: next = None if not ascending: more, less = less, more return transactions, next, more or None, less or None