aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-09-06 11:57:46 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2018-09-06 11:57:46 +0200
commitc1c942b126d199bca4927bf692e21beab1cb326a (patch)
tree8160de4ff3f67ccf66b09e22d1511d56d4130db9
parentbfda2ed94fab075be0322a741bf848b2795fc3b1 (diff)
downloadbank-c1c942b126d199bca4927bf692e21beab1cb326a.tar.gz
bank-c1c942b126d199bca4927bf692e21beab1cb326a.tar.bz2
bank-c1c942b126d199bca4927bf692e21beab1cb326a.zip
fix testcases.
according to the always-in-descending-order policy of history retrieval.
-rw-r--r--talerbank/app/tests.py2
-rw-r--r--talerbank/app/views.py18
2 files changed, 13 insertions, 7 deletions
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 43abd7c..7c246ec 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -400,7 +400,7 @@ class HistoryTestCase(TestCase):
delta="4", direction="both"),
HistoryContext(
expected_resp={
- "fields": [("row_id", 6)],
+ "fields": [("row_id", 9)],
"status": 200},
delta="+1", start="5", direction="both"),
HistoryContext(
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 99bd9e6..e0c3ed4 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -362,17 +362,23 @@ def serve_public_accounts(request, name=None, page=None):
if not user.bankaccount.is_public:
raise PrivateAccountException("Can't display public history for private account")
- num_records = query_history_raw(user.bankaccount, "both", start=-1, sign="-").count()
-
+ num_records = query_history_raw(user.bankaccount,
+ "both",
+ start=-1,
+ sign="-").count()
DELTA = 30
- youngest = 1 + DELTA * (page - 1)
+ # '//' 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, starting from 'youngest'
- history = extract_history(user.bankaccount, DELTA, youngest - 1, "+")
+ # Retrieve DELTA records younger than 'start_row' (included).
+ history = extract_history(user.bankaccount,
+ DELTA,
+ start_row - 1,
+ "+") # takes results youger than 'start_row'
- num_pages = max(num_records // DELTA, 1)
pages = list(range(1, num_pages + 1))
context = dict(