summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-12-03 17:47:41 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-12-03 17:47:41 +0100
commitdedf7f3ea7c0c8cc660f9784b279ed4002437c02 (patch)
tree5c5fa17e7abf781e80556f7ec5df444e409efe57
parenta626559464dc9cf969c7f9f5b9032065d5bb80a3 (diff)
downloadbank-dedf7f3ea7c0c8cc660f9784b279ed4002437c02.tar.gz
bank-dedf7f3ea7c0c8cc660f9784b279ed4002437c02.tar.bz2
bank-dedf7f3ea7c0c8cc660f9784b279ed4002437c02.zip
fix history query
-rw-r--r--talerbank/app/views.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 518a309..5ec770e 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -487,7 +487,6 @@ def logout_view(request):
#
# @param account the bank account object whose history is being
# extracted.
-# @param descending currently not used.
# @param delta how many history entries will be contained in the
# array (will be passed as-is to the internal routine
# @a query_history).
@@ -495,10 +494,8 @@ def logout_view(request):
# value (which is a row ID), and going to the past or to
# the future (depending on the user choice). However, this
# value itself will not be included in the history.
-# @param sign this value ("+"/"-") determines whether the history
-# entries will be younger / older than @a start.
# @return the history array.
-def extract_history(account, delta, start=UINT64_MAX):
+def extract_history(account, delta, start=None):
history = []
qs = query_history(account, "both", delta, start, "descending")
for item in qs:
@@ -678,15 +675,19 @@ def query_history_range(bank_account, direction, start, end, descending):
# entries will be younger / older than @a start.
# @param ordering "descending" or anything else (for "ascending").
def query_history(bank_account, direction, delta, start, ordering):
- def sign_filter(delta):
- if 0 > delta:
- return Q(id__lt=start)
- return Q(id__gt=start)
+ if start is None:
+ if delta > 0:
+ start = -1
+ else:
+ start = UINT64_MAX
+ if delta < 0:
+ sign_filter = Q(id__lt=start)
+ else:
+ sign_filter = Q(id__gt=start)
qs = BankTransaction.objects.filter(
direction_switch(bank_account, direction), sign_filter(delta)
)
-
order = "-id" if "descending" == ordering else "id"
return qs.order_by(order)[:abs(delta)]
@@ -769,12 +770,11 @@ def serve_history_range(request, user_account):
@login_via_headers
def serve_history(request, user_account):
args = HistoryParams(request.GET.dict())
-
qs = query_history(
user_account.bankaccount,
args.get("direction"),
args.get("delta"),
- args.get("start", UINT64_MAX),
+ args.get("start", None),
args.get("ordering", "descending")
)