mernen (owner)

Fork Of

Revisions

gist: 114638 Download_button fork
public
Public Clone URL: git://gist.github.com/114638.git
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
26
27
28
29
30
31
32
33
34
    @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