summaryrefslogtreecommitdiff
path: root/talerbank
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-04-02 18:56:47 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-04-02 18:56:47 +0200
commita3f2e328a0316fa6d44d225050007f07f7e24c32 (patch)
tree620e7740b523cb8af894c370f458706b7dab6ae4 /talerbank
parent5bde353f16d98fd01ba95dc2253e690a607c8ed3 (diff)
downloadbank-a3f2e328a0316fa6d44d225050007f07f7e24c32.tar.gz
bank-a3f2e328a0316fa6d44d225050007f07f7e24c32.tar.bz2
bank-a3f2e328a0316fa6d44d225050007f07f7e24c32.zip
New date-range-based history extractor function signature.
Diffstat (limited to 'talerbank')
-rw-r--r--talerbank/app/views.py73
1 files changed, 58 insertions, 15 deletions
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index fd8ec2a..9249cf3 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -559,9 +559,57 @@ def login_via_headers(view_func):
##
-# Helper function that sorts in a descending, or ascending
-# manner, the history elements returned by the internal routine
-# @a query_history_raw.
+# Build the DB query switch based on the "direction" history
+# argument given by the user.
+#
+# @param bank_account bank account of the user requesting history.
+# @param direction the "direction" URL parameter given by the user.
+# Note: this values got sanity-checked before this function
+# is called.
+def direction_switch(bank_account, direction):
+ direction_switch = {
+ "both": (Q(debit_account=bank_account) |
+ Q(credit_account=bank_account)),
+ "credit": Q(credit_account=bank_account),
+ "debit": Q(debit_account=bank_account),
+ "cancel+": (Q(credit_account=bank_account) &
+ Q(cancelled=True)),
+ "cancel-": (Q(debit_account=bank_account) &
+ Q(cancelled=True)),
+ }
+ return direction_switch.get(direction)
+
+##
+# Main routine querying for histories, based on _date ranges_.
+#
+# @param bank_account the bank account object whose
+# history is being extracted.
+# @param direction takes the following three values,
+# * debit: only entries where the querying user has _paid_
+# will be returned.
+# * credit: only entries where the querying user _got_
+# paid will be returned.
+# * both: both of the cases above will be returned.
+# * cancel+: only entries where the querying user cancelled
+# the _receiving_ of money will be returned.
+# * cancel-: only entries where the querying user cancelled
+# the _paying_ of money will be returned.
+# @param start timestamp of the oldest element allowed in the
+# result.
+# @param end timestamp of the youngest element allowed in the
+# result.
+# @param descending if True, then the results will have the
+# youngest entry in the first position.
+def query_history_range(bank_account,
+ direction,
+ start,
+ end,
+ descending):
+ pass
+
+
+##
+# Main routine querying for histories.
#
# @param bank_account the bank account object whose
# history is being extracted.
@@ -593,24 +641,13 @@ def query_history(bank_account,
sign,
descending=True):
- direction_switch = {
- "both": (Q(debit_account=bank_account) |
- Q(credit_account=bank_account)),
- "credit": Q(credit_account=bank_account),
- "debit": Q(debit_account=bank_account),
- "cancel+": (Q(credit_account=bank_account) &
- Q(cancelled=True)),
- "cancel-": (Q(debit_account=bank_account) &
- Q(cancelled=True)),
- }
-
sign_filter = {
"+": Q(id__gt=start),
"-": Q(id__lt=start),
}
qs = BankTransaction.objects.filter(
- direction_switch.get(direction),
+ direction_switch(bank_account, direction),
sign_filter.get(sign))
order = "-id" if descending else "id"
@@ -674,6 +711,12 @@ def serve_history(request, user_account):
if not start:
start = 0 if "+" == sign else UINT64_MAX
+ # query_history_range (bank_account,
+ # direction,
+ # start,
+ # end,
+ # ordering)
+
qs = query_history(user_account.bankaccount,
request.GET.get("direction"),
int(parsed_delta.group(2)),