[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-bank] 02/02: make 'cancel+/-' /history args exist
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-bank] 02/02: make 'cancel+/-' /history args exist |
Date: |
Thu, 07 Dec 2017 17:35:42 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository bank.
commit 6e8236731363670bbb51763329ecdb423d4946a4
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Dec 7 17:35:07 2017 +0100
make 'cancel+/-' /history args exist
---
talerbank/app/tests.py | 2 ++
talerbank/app/views.py | 23 +++++++++++++----------
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index b69fa4e..b19ceb0 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -315,6 +315,8 @@ class HistoryTestCase(TestCase):
HistoryContext(expected_resp={"status": 204},
delta="1", start="11", direction="both"),
HistoryContext(expected_resp={"status": 204},
+ delta="+1", direction="cancel+"),
+ HistoryContext(expected_resp={"status": 204},
delta="+1", direction="credit"),
HistoryContext(expected_resp={"status": 200},
delta="+1", direction="debit")):
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index bb8ed18..846458a 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -383,18 +383,21 @@ def serve_history(request, user_account):
if sign == "-":
sign_filter = Q(id__lt=start)
- # assume 'both' is given
- direction = request.GET.get("direction")
-
- query_string = Q(debit_account=user_account.bankaccount) \
- | Q(credit_account=user_account.bankaccount)
+ direction_switch = {
+ "both": Q(debit_account=user_account.bankaccount) \
+ | Q(credit_account=user_account.bankaccount),
+ "credit": Q(credit_account=user_account.bankaccount),
+ "debit": Q(debit_account=user_account.bankaccount),
+ "cancel+": Q(credit_account=user_account.bankaccount) \
+ & Q(cancelled=True),
+ "cancel-": Q(debit_account=user_account.bankaccount) \
+ & Q(cancelled=True)
+ }
+ # Sanity checks are done at the beginning, so 'direction' key
+ # (and its value as switch's key) does exist here.
+ query_string = direction_switch[request.GET["direction"]]
history = []
- if direction == "credit":
- query_string = Q(credit_account=user_account.bankaccount)
- if direction == "debit":
- query_string = Q(debit_account=user_account.bankaccount)
-
qs = BankTransaction.objects.filter(
query_string, sign_filter).order_by(
"-id" if sign == "-" else "id")[:int(parsed_delta.group(2))]
--
To stop receiving notification emails like this one, please contact
address@hidden