gnunet-svn
[Top][All Lists]
Advanced

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

[taler-bank] branch master updated: force named arguments


From: gnunet
Subject: [taler-bank] branch master updated: force named arguments
Date: Wed, 04 Dec 2019 02:12:00 +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 eb83ff4  force named arguments
eb83ff4 is described below

commit eb83ff4d4f1ee9847cfd8752371491c52b23356a
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Dec 4 02:11:53 2019 +0100

    force named arguments
---
 talerbank/app/middleware.py |  5 ++--
 talerbank/app/views.py      | 62 ++++++++++++++++++++++++++++++++-------------
 2 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/talerbank/app/middleware.py b/talerbank/app/middleware.py
index af2a748..eb34b96 100644
--- a/talerbank/app/middleware.py
+++ b/talerbank/app/middleware.py
@@ -9,7 +9,8 @@ from .models import BankAccount, BankTransaction, \
     BankAccountDoesNotExist, BankTransactionDoesNotExist
 from .views import \
     (DebitLimitException, SameAccountException,
-     LoginFailed, RejectNoRightsException, UnhandledException)
+     LoginFailed, RejectNoRightsException, UnhandledException,
+     set_profile_hint)
 
 from .schemas import \
     (JSONFieldException,
@@ -113,7 +114,7 @@ class ExceptionMiddleware:
             return JsonResponse({"ec": exception.taler_error_code,
                                  "error": exception.hint},
                                  status=exception.http_status_code)
-        request.session["profile_hint"] = True, False, exception.hint
+        set_profile_hint(request, failure=True, success=False, 
hint=exception.hint)
         return redirect(render_to)
 
 # [1] https://git.taler.net/exchange.git/tree/src/include/taler_error_codes.h
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 0466a8e..a0a58b1 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -179,22 +179,30 @@ def get_session_flag(request, name):
 
 
 ##
-# Get a hint from the session and clear it.  A 'hint' is a
-# "message" that different parts of the bank can send to each
-# other - via the state - communicating what is the state of
-# the HTTP session.
+# A session "hint" is a tuple indicating whether the
+# message is for a failure or a success, and containing
+# the message itself.
 #
 # @param request the HTTP request being served.
 # @param name hint name
 # @return the hint (a "null" one if none was found)
-def get_session_hint(request, name):
-    if name in request.session:
-        ret = request.session[name]
-        del request.session[name]
+def get_session_hint(request, hintId):
+    if hintId in request.session:
+        ret = request.session[hintId]
+        del request.session[hintId]
         return ret
-    # Fail message, success message, hint.
+
     return False, False, None
 
+def set_profile_hint(request, *, success, failure, hint):
+    set_session_hint(request, "profile_hint", success=success, 
failure=failure, hint=hint)
+
+def set_session_hint(request, hintId, *, success, failure, hint):
+    if hintId in request.session:
+        LOGGER.warning(f"Overriding a non consumed hint: {hintId}")
+        del request.session[hintId]
+    request.session[hintId] = success, failure, hint
+
 
 ##
 # Build the list containing all the predefined accounts; the
@@ -299,18 +307,24 @@ def profile_page(request):
                     account_no=wtf.cleaned_data.get("receiver")
                 ), wtf.cleaned_data.get("subject")
             )
-            request.session["profile_hint"] = False, True, "Wire transfer 
successful!"
+
+            set_profile_hint(
+                request,
+                failure=False,
+                success=True,
+                hint="Wire transfer successful!"
+            )
+
             return redirect("profile")
+
     wtf = WTForm()
-    fail_message, success_message, hint = get_session_hint(
-        request, "profile_hint"
-    )
+    is_success, is_failure, hint = get_session_hint(request, "profile_hint")
     context = dict(
         name=request.user.username,
         balance=request.user.bankaccount.amount,
         sign="-" if request.user.bankaccount.debit else "",
-        fail_message=fail_message,
-        success_message=success_message,
+        fail_message=is_failure,
+        success_message=is_success,
         hint=hint,
         precision=settings.TALER_DIGITS,
         currency=request.user.bankaccount.amount.currency,
@@ -479,7 +493,13 @@ def register(request):
             }
         )
 
-    request.session["profile_hint"] = False, True, "Registration successful!"
+    set_profile_hint(
+        request,
+        success=True,
+        failure=False,
+        hint="Registration successful!"
+    )
+
     django.contrib.auth.login(request, user)
     return redirect("profile")
 
@@ -1099,8 +1119,16 @@ def confirm_withdrawal(request, withdraw_id):
             op.amount, BankAccount.objects.get(user=request.user),
             op.selected_exchange_account, op.selected_reserve_pub
         )
-        request.session["profile_hint"] = False, True, "Withdrawal successful!"
+        
+        set_profile_hint(
+            request,
+            success=True,
+            failure=False,
+            hint="Withdrawal successful!"
+        )
+
         request.session["just_withdrawn"] = True
+
         return redirect("profile")
     if request.method == "GET":
         question, hashed_answer = make_question()

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



reply via email to

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