febuiles (owner)

Forks

Revisions

gist: 114584 Download_button fork
public
Public Clone URL: git://gist.github.com/114584.git
Embed All Files: show embed
model.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    def get_page(cls, app_id, bookmark=None):
        pagesize = 15
        next, more, less = None, None, None
        if not bookmark: # first fetch
            transactions = Transaction.app_id(app_id).order("-date").fetch(pagesize + 1)
            more = True if len(transactions) == pagesize+1 else None
        else:
            if bookmark.startswith("-"): # we're moving backwards
                date = str_to_date(bookmark[1:])
                transactions = Transaction.app_id(app_id).order("date").filter("date >", date).fetch(pagesize+1)
                more = True
                less = True if len(transactions) == pagesize+1 else None
            else:
                date = str_to_date(bookmark)
                transactions = Transaction.app_id(app_id).order("-date").filter('date <=', date).fetch(pagesize+1)
                less = True # since we're moving forward it's safe to point backwards.
                more = True if len(transactions) == pagesize+1 else None
            
        if len(transactions) == pagesize + 1: # we have one more page to show
            next = transactions[-1].date
            transactions = transactions[:pagesize]
 
        return transactions, next, more, less
    get_page = classmethod(get_page)