diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2018-12-14 14:28:16 +0100 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2018-12-14 14:28:16 +0100 |
commit | addbc2f7e908a91e76136b39e3e283a09213c448 (patch) | |
tree | e00ebefa9df44f794c5bc2334a84c539550bf7bd | |
parent | 36197b2265fea13237777ce36ce4e9584438f4c8 (diff) | |
download | bank-addbc2f7e908a91e76136b39e3e283a09213c448.tar.gz bank-addbc2f7e908a91e76136b39e3e283a09213c448.tar.bz2 bank-addbc2f7e908a91e76136b39e3e283a09213c448.zip |
Provide flag to set /history element order (asc|desc).
-rw-r--r-- | talerbank/app/schemas.py | 3 | ||||
-rw-r--r-- | talerbank/app/tests.py | 6 | ||||
-rw-r--r-- | talerbank/app/views.py | 6 |
3 files changed, 14 insertions, 1 deletions
diff --git a/talerbank/app/schemas.py b/talerbank/app/schemas.py index 1ddb684..1d756eb 100644 --- a/talerbank/app/schemas.py +++ b/talerbank/app/schemas.py @@ -131,6 +131,9 @@ HISTORY_REQUEST_SCHEMA = { "start": {"type": "string", "pattern": "^([0-9]+)$", "required": False}, + "ordering": {"type": "string", + "pattern": r"^(ascending|descending)$", + "required": False}, "direction": {"type": "string", "pattern": r"^(debit|credit|both|cancel\+|cancel-)$"}, "account_number": {"type": "string", diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py index 695ef33..24a4211 100644 --- a/talerbank/app/tests.py +++ b/talerbank/app/tests.py @@ -419,6 +419,12 @@ class HistoryTestCase(TestCase): delta="+1", start="5", direction="both"), HistoryContext( expected_resp={ + "fields": [("wt_subject", "c")], + "status": 200}, + delta="1", start=2, + direction="both", ordering="ascending"), + HistoryContext( + expected_resp={ "fields": [("wt_subject", "a")], "status": 200}, delta="-1", start=2, direction="both"), diff --git a/talerbank/app/views.py b/talerbank/app/views.py index 7a974df..53954ad 100644 --- a/talerbank/app/views.py +++ b/talerbank/app/views.py @@ -469,11 +469,15 @@ def serve_history(request, user_account): request.GET.get("delta")) sign = parsed_delta.group(1) + # Ordering. + ordering = request.GET.get("ordering", "descending") + qs = query_history(user_account.bankaccount, request.GET.get("direction"), int(parsed_delta.group(2)), int(request.GET.get("start", MAX_UINT64)), - sign if sign else "+") + sign if sign else "+", + "descending" == ordering) history = [] cancelled = request.GET.get("cancelled", "show") |