gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-bank] 02/05: set the state to implement the "see nex


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] 02/05: set the state to implement the "see next page" feature useful when an account's history is too long.
Date: Mon, 15 Jan 2018 17:08:02 +0100

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

marcello pushed a commit to branch master
in repository bank.

commit 3562cf0a2521e50e6b3490e3f2c260bdab972f9b
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Jan 15 14:03:54 2018 +0100

    set the state to implement the "see next page" feature
    useful when an account's history is too long.
---
 talerbank/app/templates/public_accounts.html |  3 ++
 talerbank/app/urls.py                        | 31 +++++++++++-------
 talerbank/app/views.py                       | 47 +++++++++++++++++++++++++---
 3 files changed, 65 insertions(+), 16 deletions(-)

diff --git a/talerbank/app/templates/public_accounts.html 
b/talerbank/app/templates/public_accounts.html
index e92edb6..a059ca2 100644
--- a/talerbank/app/templates/public_accounts.html
+++ b/talerbank/app/templates/public_accounts.html
@@ -78,6 +78,9 @@
           {% endfor %}
           </tbody>
         </table>
+        {% for pagej in pages %}
+          <a href="{{ url("public-accounts", name=account.user.username, 
page=pagej) }}">pagej</a>
+        {% endfor %}
       {% else %}
         <p>No history for account #{{ selected_account.number }} ({{ 
selected_account.name}}) yet</p>
       {% endif %}
diff --git a/talerbank/app/urls.py b/talerbank/app/urls.py
index c44c7c3..b0a0e52 100644
--- a/talerbank/app/urls.py
+++ b/talerbank/app/urls.py
@@ -1,16 +1,19 @@
 #  This file is part of TALER
 #  (C) 2014, 2015, 2016 INRIA
 #
-#  TALER is free software; you can redistribute it and/or modify it under the
-#  terms of the GNU Affero General Public License as published by the Free 
Software
-#  Foundation; either version 3, or (at your option) any later version.
+#  TALER is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation; either version 3, or
+# (at your option) any later version.
 #
-#  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
-#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
-#  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#  TALER is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
 #
-#  You should have received a copy of the GNU General Public License along with
-#  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+#  You should have received a copy of the GNU General Public
+# License along with TALER; see the file COPYING.  If not, see
+# <http://www.gnu.org/licenses/>.
 #
 #  @author Marcello Stanisci
 
@@ -20,9 +23,11 @@ from . import views
 
 urlpatterns = [
     url(r'^', include('talerbank.urls')),
-    url(r'^$', RedirectView.as_view(pattern_name="profile"), name="index"),
+    url(r'^$', RedirectView.as_view(pattern_name="profile"),
+        name="index"),
     url(r'^favicon\.ico$', views.ignore),
-    url(r'^admin/add/incoming$', views.add_incoming, name="add-incoming"),
+    url(r'^admin/add/incoming$', views.add_incoming,
+        name="add-incoming"),
     url(r'^login/$', views.login_view, name="login"),
     url(r'^logout/$', views.logout_view, name="logout"),
     url(r'^accounts/register/$', views.register, name="register"),
@@ -30,10 +35,12 @@ urlpatterns = [
     url(r'^history$', views.serve_history, name="history"),
     url(r'^reject$', views.reject, name="reject"),
     url(r'^withdraw$', views.withdraw_nojs, name="withdraw-nojs"),
-    url(r'^public-accounts$', views.serve_public_accounts, 
name="public-accounts"),
+    url(r'^public-accounts$', views.serve_public_accounts,
+        name="public-accounts"),
     url(r'^public-accounts/(?P<name>[a-zA-Z0-9 ]+)$',
         views.serve_public_accounts,
         name="public-accounts"),
-    url(r'^pin/question$', views.pin_tan_question, name="pin-question"),
+    url(r'^pin/question$', views.pin_tan_question,
+        name="pin-question"),
     url(r'^pin/verify$', views.pin_tan_verify, name="pin-verify"),
     ]
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index a41c072..ff13a21 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -321,6 +321,7 @@ def logout_view(request):
 
 
 def extract_history(account, delta=None, start=-1, sign="+"):
+    print(account, delta, start, sign)
     history = []
     qs = query_history(account, "both", delta, start, sign)
     for item in qs:
@@ -344,17 +345,43 @@ def extract_history(account, delta=None, start=-1, 
sign="+"):
     return history
 
 
-def serve_public_accounts(request, name=None):
+def serve_public_accounts(request, name=None, page=None):
     if not name:
         name = settings.TALER_PREDEFINED_ACCOUNTS[0]
     user = User.objects.get(username=name)
+
+    if "public_history_count" not in request.session:
+        qs = extract_history(user.bankaccount, sign="-")
+        youngest = -1
+        if qs:
+            youngest = qs[0]["row_id"]
+        request.session["public_history_account"] = \
+            len(qs), youngest
+
+    DELTA = 100
+    youngest = request.session["public_history_account"][1]
+    # normalize page
+    if not page or page in [0, 1]:
+        page = 1
+    # page 0 and 1 give both the youngest 100 records.
+    if page > 1:
+        youngest = youngest + (DELTA * page)
     if not user.bankaccount.is_public:
         request.session["public_accounts_hint"] = \
             True, False, "Could not query private accounts!"
     fail_message, success_message, hint = \
         get_session_hint(request, "public_accounts_hint")
     public_accounts = BankAccount.objects.filter(is_public=True)
-    history = extract_history(user.bankaccount)
+
+    # Retrieve DELTA records older than 'start'.
+    history = extract_history(
+        user.bankaccount, DELTA,
+        -1 if youngest < 2 else youngest, "-")
+
+    num_pages = request.session["public_history_account"][0] / DELTA
+    pages = list(
+        range(max(1, page - 3), min(page + 3, int(num_pages))))
+
     context = dict(
         public_accounts=public_accounts,
         selected_account=dict(
@@ -364,6 +391,7 @@ def serve_public_accounts(request, name=None):
             name=name,
             number=user.bankaccount.account_no,
             history=history,
+            pages=pages
         )
     )
     return render(request, "public_accounts.html", context)
@@ -400,14 +428,25 @@ def query_history(bank_account, direction, delta, start, 
sign):
                       & Q(cancelled=True),
         "cancel-": Q(debit_account=bank_account) \
                       & Q(cancelled=True)}
+
     sign_filter = {
         "+": Q(id__gt=start),
-        "-": Q(id__lt=start)    
+        "-": Q(id__lt=start),
+        "*": Q(),
+        "x": not Q(),
     }
+
+    # Handle special case.
+    if start == -1: # can only retrieve older records.
+        sign = "*"
+        if sign == "+": # no result is younger than the youngest.
+            sign = "x"
+
     return BankTransaction.objects.filter(
         direction_switch.get(direction),
         sign_filter.get(sign)).order_by(
-            "-id" if sign == "-" else "id")[:delta]
+            # '-id' does descending ordering.
+            "-id" if sign in ["-", "*"] else "id")[:delta]
 
 @require_GET
 @login_via_headers

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



reply via email to

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