Skip to content

Instantly share code, notes, and snippets.

@mernen
Forked from febuiles/model.py
Created May 20, 2009 05:39
Show Gist options
  • Save mernen/114638 to your computer and use it in GitHub Desktop.
Save mernen/114638 to your computer and use it in GitHub Desktop.
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment