diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2018-09-06 13:47:51 +0200 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2018-09-06 13:49:47 +0200 |
commit | ef4a846a1208de253cce599ce00bdbd0ceb3252c (patch) | |
tree | f07fab94c209047cdba91e2f5d59aeca0f8f61e1 /talerbank/app/views.py | |
parent | c1c942b126d199bca4927bf692e21beab1cb326a (diff) | |
download | bank-ef4a846a1208de253cce599ce00bdbd0ceb3252c.tar.gz bank-ef4a846a1208de253cce599ce00bdbd0ceb3252c.tar.bz2 bank-ef4a846a1208de253cce599ce00bdbd0ceb3252c.zip |
Paginator.
Do not use 'start_row' anymore when retrieving
pages higher than number 1. Rather, get all the
previous records and discard those already seen.
Although a bit wasteful, this simplifies a
lot the calculation of the first row to be seen
on the next page. And possibly not more wasteful
than calculating the last row for each page.
Diffstat (limited to 'talerbank/app/views.py')
-rw-r--r-- | talerbank/app/views.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/talerbank/app/views.py b/talerbank/app/views.py index e0c3ed4..6a09edf 100644 --- a/talerbank/app/views.py +++ b/talerbank/app/views.py @@ -352,7 +352,9 @@ def extract_history(account, delta=None, start=-1, sign="+"): def serve_public_accounts(request, name=None, page=None): try: - page = int(page) + page = abs(int(page)) + if page == 0: + raise Exception except Exception: page = 1 @@ -364,20 +366,19 @@ def serve_public_accounts(request, name=None, page=None): num_records = query_history_raw(user.bankaccount, "both", - start=-1, - sign="-").count() + start=-1, # makes sign ignored. + sign="+").count() DELTA = 30 # '//' operator is NO floating point. num_pages = max(num_records // DELTA, 1) - start_row = 1 + (DELTA * (page - 1)) public_accounts = BankAccount.objects.filter(is_public=True) # Retrieve DELTA records younger than 'start_row' (included). history = extract_history(user.bankaccount, - DELTA, - start_row - 1, - "+") # takes results youger than 'start_row' + DELTA * page, + -1, + "+")[DELTA * (page - 1):(DELTA * page)] pages = list(range(1, num_pages + 1)) @@ -444,7 +445,7 @@ def query_history_raw(bank_account, direction, start, sign): } # Handle special case. - if start == -1: # return 'delta' youngest records. + if start < 0: # return all the records. sign = "+" return BankTransaction.objects.filter( |