gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: Paginator.


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: Paginator.
Date: Thu, 06 Sep 2018 13:50:55 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new ef4a846  Paginator.
ef4a846 is described below

commit ef4a846a1208de253cce599ce00bdbd0ceb3252c
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Sep 6 13:47:51 2018 +0200

    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.
---
 talerbank/app/views.py | 17 +++++++++--------
 1 file 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(

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]