gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: implementing 'direction


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: implementing 'direction' in /history
Date: Wed, 03 May 2017 22:08:45 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new 27db538  implementing 'direction' in /history
27db538 is described below

commit 27db53816502ac5b45aa6a45d7fdc831810b0405
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed May 3 22:08:35 2017 +0200

    implementing 'direction' in /history
---
 talerbank/app/tests.py |  4 ++--
 talerbank/app/views.py | 58 ++++++++++++++++++++++++++++++--------------------
 2 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 86ef66a..4cb584f 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -102,7 +102,7 @@ class HistoryTestCase(TestCase):
     def test_history(self):
         c = Client()
         response = c.post(reverse("history", urlconf=urls),
-                          data= '{"auth": \
+                          data='{"auth": \
                                    {"type": "basic", \
                                     "data": \
                                       {"username": "User", \
@@ -111,7 +111,7 @@ class HistoryTestCase(TestCase):
                                   "delta": 4, \
                                   "direction": "whatever"}',
                           content_type="application/json")
-        self.assertEqual(200, response.status_code)
+        self.assertEqual(400, response.status_code)
 
 
 # This tests whether a bank account goes red and then
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index d839a11..0d1c4d9 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -326,8 +326,6 @@ def public_accounts(request, name=None):
     )
     return render(request, "public_accounts.html", context)
 
-# Although this call doesn't change the server's state,
-# it uses POST because it takes a password among its parameters
 @require_POST
 def history(request):
     """
@@ -347,28 +345,42 @@ def history(request):
     start = data.get("start", 0)
     delta = data.get("delta", 0)
     
-    qs = 
BankTransaction.objects.filter((Q(debit_account=user_account.bankaccount) |
-                                         
Q(credit_account=user_account.bankaccount)) &
-                                         Q(id__gt=0))[:delta]
-
-    logger.info("Found %d results for user '%s'" % (len(qs), 
user_account.username))
-    
+    direction = data.get("direction")
     history = []
-
-    for entry in qs:
-
-        counterpart = entry.credit_account.user.username
-        sign = "-"
-
-        if entry.credit_account.user.username == user_account.username:
-            counterpart = entry.debit_account.user.username
-            sign = "+"
-
-        history.append(dict(counterpart=counterpart,
-                            amount=entry.amount_obj,
-                            sign=sign))
-    logger.info(json.dumps(history))
-    return HttpResponse(200)
+    if not direction:
+        qs = 
BankTransaction.objects.filter((Q(debit_account=user_account.bankaccount) |
+                                             
Q(credit_account=user_account.bankaccount)) &
+                                             Q(id__gt=start))[:delta]
+        logger.info("Found %d results for user '%s'" % (len(qs), 
user_account.username))
+        for entry in qs:
+            counterpart = entry.credit_account.user.username
+            sign = "-"
+            if entry.credit_account.user.username == user_account.username:
+                counterpart = entry.debit_account.user.username
+                sign = "+"
+            history.append(dict(counterpart=counterpart,
+                                amount=entry.amount_obj,
+                                sign=sign))
+        logger.info(json.dumps(history))
+        return HttpResponse(200)
+
+    if "debit" == direction:
+        qs = 
BankTransaction.objects.filter(Q(debit_account=user_account.bankaccount) &
+                                             Q(id__gt=start))[:delta]
+        for entry in qs:
+            history.append(dict(amount=entry.amount_obj,
+                                 
counterpart=entry.credit_account.user.username))
+        return JsonResponse(dict(data=history), 200)
+
+    if "credit" == direction:
+        qs = 
BankTransaction.objects.filter(Q(credit_account=user_account.bankaccount) &
+                                             Q(id__gt=start))[:delta]
+        for entry in qs:
+            history.append(dict(amount=entry.amount_obj,
+                                 
counterpart=entry.debit_account.user.username))
+        return JsonResponse(dict(data=history), 200)
+
+    return JsonResponse(dict(error="Unknown 'direction' indication"), 
status=400)
 
 
 def auth_and_login(auth_obj):

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]