gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-bank] 09/12: 5543. Let Jinja render abnormal balance


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] 09/12: 5543. Let Jinja render abnormal balances.
Date: Fri, 29 Mar 2019 18:08:28 +0100

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

marcello pushed a commit to branch master
in repository bank.

commit efd3fa0187f9985537407f243ed6e0eeb89e73ed
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Feb 8 17:23:03 2019 +0100

    5543.  Let Jinja render abnormal balances.
---
 talerbank/app/templates/profile_page.html |  7 ++++++-
 talerbank/app/views.py                    |  3 +--
 talerbank/jinja2.py                       | 16 ++++++++++++++++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/talerbank/app/templates/profile_page.html 
b/talerbank/app/templates/profile_page.html
index e5f9abc..8bf0baa 100644
--- a/talerbank/app/templates/profile_page.html
+++ b/talerbank/app/templates/profile_page.html
@@ -38,7 +38,12 @@
 {% block content %}
   <section id="menu">
     <p>Account: # {{ account_no }}</p>
-    <p>Current balance: <b>{{ sign }} {{ balance }}</b></p>
+    {% if is_valid_amount(balance) %}
+      <p>Current balance: <b>{{ sign }} {{ amount_stringify(balance) }}</b></p>
+    {% else %}
+      <p class="informational-fail">Current balance: <b>{{ INVALID AMOUNT, 
PLEASE REPORT }}</b></p>
+    {% endif%}
+
   </section>
   <section id="main">
     <article>
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 6d87e22..2914341 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -247,8 +247,7 @@ def profile_page(request):
     fail_message, success_message, hint = get_session_hint(request, 
"profile_hint")
     context = dict(
         name=request.user.username,
-        balance=request.user.bankaccount.amount.stringify(
-            settings.TALER_DIGITS, pretty=True),
+        balance=request.user.bankaccount.amount,
         sign="-" if request.user.bankaccount.debit else "",
         fail_message=fail_message,
         success_message=success_message,
diff --git a/talerbank/jinja2.py b/talerbank/jinja2.py
index b646162..9c2c52e 100644
--- a/talerbank/jinja2.py
+++ b/talerbank/jinja2.py
@@ -20,6 +20,7 @@
 #  @brief Extends the Jinja2 API with custom functions.
 
 import os
+import math
 from urllib.parse import urlparse
 from django.urls import reverse, get_script_prefix
 from django.conf import settings
@@ -108,6 +109,19 @@ def env_get(name, default=None):
 #
 # @param options opaque argument (?) given from the caller.
 # @return Jinja2-specific object that contains the new definitions.
+def is_valid_amount(amount):
+    if math.isnan(amount.value):
+        return False
+
+
+##
+# Stringifies amount.
+#
+# @param amount amount object.
+# @return amount pretty string.
+def amount_stringify(amount):
+    return amount.stringify(settings.TALER_DIGITS, pretty=True)
+
 def environment(**options):
     env = Environment(**options)
     env.globals.update({
@@ -115,5 +129,7 @@ def environment(**options):
         'url': url,
         'settings_value': settings_value,
         'env': env_get,
+        'is_valid_amount': is_valid_amount
+        'amount_stringify': amount_stringify
     })
     return env

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



reply via email to

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