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: done with linting


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: done with linting
Date: Tue, 05 Dec 2017 17:28:26 +0100

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 4bacbbe  done with linting
4bacbbe is described below

commit 4bacbbeb8d6a3fde2abcbe2806753615b08dba84
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Dec 5 17:28:12 2017 +0100

    done with linting
---
 talerbank/app/views.py | 151 ++++++++++++++++++++++++-------------------------
 1 file changed, 75 insertions(+), 76 deletions(-)

diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 7f8aed4..8e2e452 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -505,84 +505,83 @@ class WireTransferException(Exception):
         self.response = response
         super().__init__()
 
-def wire_transfer_exc_handler(view_func):
+def wire_transfer(amount, debit_account, credit_account, subject, **kwargs):
+
     def err_cb(exc, resp):
         LOGGER.error(str(exc))
         raise WireTransferException(exc, resp)
-    def _decorator(*args, request=None, session_expand=None):
-        try:
-            return view_func(*args)
-        except (CurrencyMismatch, BadFormatAmount) as exc:
-            err_cb(exc, JsonResponse({"error": "internal server error"},
-                                     status=500))
-        except DebtLimitExceededException as exc:
-            if request:
-                if session_expand:
-                    request.session.update(session_expand)
-                if request.path == "/pin/verify":
-                    err_cb(exc, redirect("profile"))
-            else:
-                err_cb(exc, JsonResponse({"error": "Unallowed debit"},
-                                         status=403))
-        except SameAccountException as exc:
-            err_cb(exc, JsonResponse({"error": "sender account == receiver 
account"},
-                                     status=422))
-    return wraps(view_func)(_decorator)
-
address@hidden
-def wire_transfer(amount, debit_account, credit_account, subject, **kwargs):
-    LOGGER.info("%s => %s, %s, %s" %
-                (debit_account.account_no,
-                 credit_account.account_no,
-                 amount.stringify(2),
-                 subject))
-    if debit_account.pk == credit_account.pk:
-        LOGGER.error("Debit and credit account are the same!")
-        raise SameAccountException()
-
-    transaction_item = BankTransaction(amount=amount,
-                                       credit_account=credit_account,
-                                       debit_account=debit_account,
-                                       subject=subject)
-    if debit_account.debit:
-        debit_account.amount.add(amount)
-
-    elif -1 == Amount.cmp(debit_account.amount, amount):
-        debit_account.debit = True
-        tmp = Amount(**amount.dump())
-        tmp.subtract(debit_account.amount)
-        debit_account.amount.set(**tmp.dump())
-    else:
-        debit_account.amount.subtract(amount)
-
-    if not credit_account.debit:
-        credit_account.amount.add(amount)
-    elif Amount.cmp(amount, credit_account.amount) == 1:
-        credit_account.debit = False
-        tmp = Amount(**amount.dump())
-        tmp.subtract(credit_account.amount)
-        credit_account.amount.set(**tmp.dump())
-    else:
-        credit_account.amount.subtract(amount)
-
-    # Check here if any account went beyond the allowed
-    # debit threshold.
-
-    threshold = Amount.parse(settings.TALER_MAX_DEBT)
-    if debit_account.user.username == "Bank":
-        threshold = Amount.parse(settings.TALER_MAX_DEBT_BANK)
-    if Amount.cmp(debit_account.amount, threshold) == 1 \
-        and Amount.cmp(Amount(settings.TALER_CURRENCY), threshold) != 0 \
-        and debit_account.debit:
-        LOGGER.info("Negative balance '%s' not allowed.\
-                    " % json.dumps(debit_account.amount.dump()))
-        LOGGER.info("%s's threshold is: '%s'.\
-                    " % (debit_account.user.username, 
json.dumps(threshold.dump())))
-        raise DebtLimitExceededException()
 
-    with transaction.atomic():
-        debit_account.save()
-        credit_account.save()
-        transaction_item.save()
+    def wire_transfer_internal(amount, debit_account, credit_account, subject):
+        LOGGER.info("%s => %s, %s, %s" %
+                    (debit_account.account_no,
+                     credit_account.account_no,
+                     amount.stringify(2),
+                     subject))
+        if debit_account.pk == credit_account.pk:
+            LOGGER.error("Debit and credit account are the same!")
+            raise SameAccountException()
+
+        transaction_item = BankTransaction(amount=amount,
+                                           credit_account=credit_account,
+                                           debit_account=debit_account,
+                                           subject=subject)
+        if debit_account.debit:
+            debit_account.amount.add(amount)
+
+        elif -1 == Amount.cmp(debit_account.amount, amount):
+            debit_account.debit = True
+            tmp = Amount(**amount.dump())
+            tmp.subtract(debit_account.amount)
+            debit_account.amount.set(**tmp.dump())
+        else:
+            debit_account.amount.subtract(amount)
+
+        if not credit_account.debit:
+            credit_account.amount.add(amount)
+        elif Amount.cmp(amount, credit_account.amount) == 1:
+            credit_account.debit = False
+            tmp = Amount(**amount.dump())
+            tmp.subtract(credit_account.amount)
+            credit_account.amount.set(**tmp.dump())
+        else:
+            credit_account.amount.subtract(amount)
+
+        # Check here if any account went beyond the allowed
+        # debit threshold.
+
+        threshold = Amount.parse(settings.TALER_MAX_DEBT)
+        if debit_account.user.username == "Bank":
+            threshold = Amount.parse(settings.TALER_MAX_DEBT_BANK)
+        if Amount.cmp(debit_account.amount, threshold) == 1 \
+            and Amount.cmp(Amount(settings.TALER_CURRENCY), threshold) != 0 \
+            and debit_account.debit:
+            LOGGER.info("Negative balance '%s' not allowed.\
+                        " % json.dumps(debit_account.amount.dump()))
+            LOGGER.info("%s's threshold is: '%s'.\
+                        " % (debit_account.user.username, 
json.dumps(threshold.dump())))
+            raise DebtLimitExceededException()
+
+        with transaction.atomic():
+            debit_account.save()
+            credit_account.save()
+            transaction_item.save()
+
+        return transaction_item
 
-    return transaction_item
+    try:
+        return wire_transfer_internal(amount, debit_account, credit_account, 
subject)
+    except (CurrencyMismatch, BadFormatAmount) as exc:
+        err_cb(exc, JsonResponse({"error": "internal server error"},
+                                 status=500))
+    except DebtLimitExceededException as exc:
+        if kwargs.get("request"):
+            if kwargs.get("session_expand"):
+                kwargs["request"].session.update(kwargs["session_expand"])
+            if kwargs["request"].request.path == "/pin/verify":
+                err_cb(exc, redirect("profile"))
+        else:
+            err_cb(exc, JsonResponse({"error": "Unallowed debit"},
+                                     status=403))
+    except SameAccountException as exc:
+        err_cb(exc, JsonResponse({"error": "sender account == receiver 
account"},
+                                 status=422))

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



reply via email to

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